-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDuyet cac dinh tru.cpp
51 lines (49 loc) · 939 Bytes
/
Duyet cac dinh tru.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<stack>
using namespace std;
int a[1000][1000],n,check[1000];
void dfs(int u){
stack<int> st;
st.push(u);
check[u]=1;
while(!st.empty()){
int s=st.top();
st.pop();
for(int v=1;v<=n;++v){
if(a[s][v]&&!check[v]){
st.push(s);
st.push(v);
check[v]=1;
break;
}
}
}
}
void re_init(){
for(int i=1;i<=n;++i) check[i]=0;
}
int dem(){
int count =0;
for(int i=1;i<=n;++i){
if(!check[i]){
++count;
dfs(i);
}
}return count;
}
void tru(){
int tplt=dem();
re_init();
for(int u=1;u<=n;++u){
check[u]=1;
int ans = dem();
if(ans > tplt ) cout << u << " ";
re_init();
}
}
int main(){
cin >> n;
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j) cin >> a[i][j];
}tru();
}