-
Notifications
You must be signed in to change notification settings - Fork 0
/
P11403.cpp
53 lines (43 loc) · 939 Bytes
/
P11403.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
52
53
#include <iostream>
#include <cstring>
using namespace std;
int graph[101][101] = {};
int check[101] = {};
int result[101][101] = {};
int N;
int point;
void dfs(int start) {
for (int i = 1; i <= N; i++) {
int node = graph[start][i];
if(!node) continue;
if(check[i]) continue;
check[i] = 1;
result[point][i] = 1;
dfs(i);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= N; j++) {
int a;
cin >> a;
if(a) graph[i][j] = 1;
}
}
for(int i = 1; i <= N; i++) {
memset(check, 0, sizeof(check));
point = i;
dfs(i);
}
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= N; j++) {
cout << result[i][j] << " ";
}
cout << "\n";
}
return 0;
}