-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11403.cpp
More file actions
36 lines (34 loc) · 850 Bytes
/
11403.cpp
File metadata and controls
36 lines (34 loc) · 850 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int graph[101][101];
int res[101][101];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
cin >> graph[i][j];
for (int st = 1; st <= N; st++) {
int visited[101] = { 0, };
queue<int> Q;
Q.push(st);
while (!Q.empty()) {
int cur = Q.front();
Q.pop();
for (int i = 1; i <= N; i++) {
if (graph[cur][i] && !visited[i]) {
Q.push(i);
visited[i] = 1;
res[st][i] = 1;
}
}
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++)
cout << res[i][j];
cout << '\n';
}
}