-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (43 loc) · 973 Bytes
/
Copy pathmain.cpp
File metadata and controls
45 lines (43 loc) · 973 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
37
38
39
40
41
42
43
44
45
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
int N, input;
vector<int> graph[101];
bool check[101];
int visited[101][101];
int dr[] = {0,0,1,-1};
int dc[] = {1,-1,0,0};
void bfs(int start){
queue<int> q;
for(int i=0; i<graph[start].size(); i++) {
int next = graph[start][i];
if(check[next] == false) {
check[next] = true;
visited[start][next] = 1;
visited[next][start] = 1;
q.push(next);
}
}
}
int main() {
scanf("%d", &N);
for(int i=0; i<N; i++){
for(int j=i; j<N; j++){
scanf("%d", &input);
if(input == 1) {
graph[i].push_back(j);
graph[j].push_back(i);
}
}
}
for(int i=0; i<N; i++)
bfs(i);
for(int i=0; i<N; i++){
for(int j=0; j<N; j++) {
printf("%d ", visited[i][j]);
}
puts("");
}
return 0;
}