-
Notifications
You must be signed in to change notification settings - Fork 2
/
1719_josueyeon.cpp
91 lines (75 loc) · 1.58 KB
/
1719_josueyeon.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Shortest path: 플로이드 워
#include <iostream>
#include <vector>
using namespace std;
int graph[201][201];
int dist[201][201];
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
// N(집 크기)
int n, m;
cin>>n>>m;
for(int i = 0;i < 201;i++)
{
for(int j = 0;j < 201;j++)
{
if (i == j)
{셜
dist[i][j] = 0;
graph[i][j] = 0;
}
else
{
dist[i][j] = 0;
graph[i][j] = 1e9;
}
}
}
for(int i = 0;i < m;i++)
{
int a, b, cost;
cin>>a>>b>>cost;
graph[a][b] = cost;
graph[b][a] = cost;
dist[a][b] = b;
dist[b][a] = a;
}
for(int i = 1;i <= n;i++)
{
for(int a = 1;a <= n;a++)
{
for(int b = 1;b <= n;b++)
{
if (graph[a][b] > graph[a][i] + graph[i][b])
{
graph[a][b] = graph[a][i] + graph[i][b];
// 거쳐가는 경로의 가장 앞의 경로로 업데이트
dist[a][b] = dist[a][i];
}
}
}
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
if (i == j)
cout<<'-'<<" ";
else
cout<<dist[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
/*
- 2 1 5 5 7
2 - 3 5 3 5
1 3 - 4 6 7
5 5 4 - 6 4
5 3 6 6 - 2
7 5 7 4 2 -
*/