-
Notifications
You must be signed in to change notification settings - Fork 557
/
11404.cpp
37 lines (32 loc) · 799 Bytes
/
11404.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
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : -
// http://boj.kr/610baea46f8d403fa58b632b29389ae1
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int d[105][105];
int n, m;
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++)
fill(d[i], d[i]+1+n, INF);
while(m--){
int a,b,c;
cin >> a >> b >> c;
d[a][b] = min(d[a][b], c);
}
for(int i = 1; i <= n; i++) d[i][i] = 0;
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
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';
}
}