-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11403.cpp
More file actions
57 lines (49 loc) · 1.03 KB
/
11403.cpp
File metadata and controls
57 lines (49 loc) · 1.03 KB
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
/**
* @file 11403.cpp
* @brief 경로 찾기
* @author Sam Kim (samkim2626@gmail.com)
*/
#include <iostream>
using namespace std;
int graph[101][101];
int path[101][101];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> graph[i][j];
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
for (int k = 1; k <= n; k++)
{
if (graph[j][k] == 1 || graph[j][i] + graph[i][k] == 2)
{
path[j][k] = 1;
}
if (path[j][k] == 1 || path[j][i] + path[i][k] == 2)
{
graph[j][k] = 1;
}
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cout << path[i][j] << ' ';
}
cout << '\n';
}
return 0;
}