-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_11404.cpp
More file actions
52 lines (46 loc) · 964 Bytes
/
back_11404.cpp
File metadata and controls
52 lines (46 loc) · 964 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
#include <iostream>
#include <algorithm>
using namespace std;
int maxx = 99999999;
int city[101][101];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i != j)
city[i][j] = maxx;
}
}
for (int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
city[a][b] = min(city[a][b],c);
}
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
city[i][j] = min(city[i][j], city[i][k] + city[k][j]);
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (city[i][j] == maxx)
cout << "0 ";
else
cout << city[i][j] << " ";
}
cout << "\n";
}
return 0;
}