-
Notifications
You must be signed in to change notification settings - Fork 0
/
11403.cpp
43 lines (40 loc) · 909 Bytes
/
11403.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
#include<iostream>
#include<queue>
using namespace std;
int main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
bool graph[101][101] = {0, };
bool answer[101][101] = {0, };
//입력
cin >> n;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> graph[i][j];
}
}
//bfs
for(int i = 0; i < n; i++){
bool visited[101] = {0, };
queue<int>s;
s.push(i);
while(!s.empty()){
for(int j = 0; j < n; j++){
if(graph[s.front()][j] && !visited[j]){
visited[j] = 1;
answer[i][j] = 1;
s.push(j);
}
}
s.pop();
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cout << answer[i][j] << ' ';
}
cout <<'\n';
}
}