-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboj.11404.cc
52 lines (44 loc) · 980 Bytes
/
boj.11404.cc
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 987654321
void printCost(vector<vector<int>> &cost, int n)
{
for(int i = 0; i<n; ++i)
{
for(int l = 0; l<n; ++l)
{
printf("%d ", cost[i][l]!=INF?cost[i][l]:0);
}
printf("\n");
}
}
int main(void)
{
int n, m;
scanf("%d", &n);
scanf("%d", &m);
vector<vector<int>> cost(n, vector<int>(n, INF));
for(int i = 0; i<n; ++i)
{
cost[i][i] = 0;
}
for(int i = 0, a, b, c; i<m; ++i)
{
scanf("%d %d %d", &a, &b, &c);
cost[a][b] = min(cost[--a][--b], c);
}
for(int midium =0; midium<n; ++midium)
{
for(int i = 0; i<n; ++i)
{
for(int l = 0; l<n; ++l)
{
cost[i][l] = min(cost[i][l],
cost[i][midium] + cost[midium][l]);
}
}
}
printCost(cost, n);
return 0;
}