-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11403.cpp
More file actions
58 lines (54 loc) · 898 Bytes
/
11403.cpp
File metadata and controls
58 lines (54 loc) · 898 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
46
47
48
49
50
51
52
53
54
55
56
57
58
// 11403.경로 찾기
// 2019.05.22
// BFS, DFS, 플로이드 와샬 알고리즘
#include<iostream>
#include<queue>
using namespace std;
int visit[101][101]; // 방문유무를 저장하는 배열
int v[101][101];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> v[i][j];
}
}
queue<int> q;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (v[i][j] == 1) // 각 행을 조사하면서 값이 1인것을 먼저 다 넣음
{
q.push(j);
}
}
while (!q.empty()) // BFS
{
int tmp = q.front();
q.pop();
for (int j = 0; j < n; j++)
{
if (v[tmp][j] == 1 && visit[i][j] == 0)
{
v[i][j] = 1;
visit[i][j] = 1;
q.push(j);
}
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << v[i][j] << " ";
}
cout << endl;
}
return 0;
}