-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11404.cpp
More file actions
55 lines (51 loc) · 1.09 KB
/
Copy path11404.cpp
File metadata and controls
55 lines (51 loc) · 1.09 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 987654321
using namespace std;
vector<vector<int>> dist;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int N, M, a, b, c;
cin >> N >> M;
dist.assign(N + 1, vector<int>(N + 1, INF));
for (int i = 1; i <= N; i++)
{
dist[i][i] = 0;
}
while (M--)
{
cin >> a >> b >> c;
dist[a][b] = min(dist[a][b], c);
}
for (int k = 1; k <= N; k++)
{
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
if (dist[i][k] == INF || dist[k][j] == INF)
continue;
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
if (dist[i][j] == INF)
{
cout << "0 ";
}
else
{
cout << dist[i][j] << " ";
}
}
cout << endl;
}
return 0;
}