forked from encrypted-def/BOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
11404.cpp
35 lines (35 loc) · 1000 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
#include <stdio.h>
#include <algorithm>
using namespace std;
int D[101][101]; // D[i][j] : i에서 j로 가는 최소비용
int main(void) {
int n, m;
scanf("%d %d", &n, &m);
while (m--) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (D[a][b] == 0)
D[a][b] = c;
else
D[a][b] = min(D[a][b], c);
}
for (int chk = 1; chk <= n; chk++) {
for (int st = 1; st <= n; st++) {
for (int en = 1; en <= n; en++) {
if (st == en)
continue;
if (D[st][chk] == 0 || D[chk][en] == 0)
continue;
if (D[st][en] == 0)
D[st][en] = D[st][chk] + D[chk][en];
else
D[st][en] = min(D[st][en], D[st][chk] + D[chk][en]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
printf("%d ", D[i][j]);
printf("\n");
}
}