forked from encrypted-def/BOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11403.cpp
More file actions
35 lines (35 loc) · 870 Bytes
/
11403.cpp
File metadata and controls
35 lines (35 loc) · 870 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
#include <stdio.h>
#include <queue>
using namespace std;
int main(void){
int N;
int edge[101][101];
int reach[101][101] = {0, };
scanf("%d", &N);
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++)
scanf("%d", &edge[i][j]);
}
for(int st = 1; st <= N; st++){
int isVisited[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(edge[cur][i] && !isVisited[i]){
Q.push(i);
reach[st][i] = 1;
isVisited[i] = true;
}
}
}
}
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
printf("%d ", reach[i][j]);
}
printf("\n");
}
}