-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj_11404.cpp
More file actions
55 lines (46 loc) · 954 Bytes
/
boj_11404.cpp
File metadata and controls
55 lines (46 loc) · 954 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
//<11404>번 : <플로이드>
#include <bits/stdc++.h>
#define INF 100000000
using namespace std;
int d[101][101];
int n, m;
void floyd()
{
for(int i = 1; i <= n; i++)
d[i][i] = 0;
for(int v = 1; v <= n; v++)
{
for(int s = 1; s <= n; s++)
{
for(int t = 1; t <= n; t++)
{
if(d[s][v] + d[v][t] < d[s][t])
d[s][t] = d[s][v] + d[v][t];
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
fill(d[0], d[101], INF);
for(int i = 0; i < m; i++)
{
int u, v, w;
cin >> u >> v >> w;
d[u][v] = min(d[u][v], w);
}
floyd();
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n ; j++)
{
if(d[i][j] == INF) cout << 0 << ' ';
else cout << d[i][j] << ' ';
}
cout << '\n';
}
return 0;
}