-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloyd.cpp
More file actions
51 lines (42 loc) · 764 Bytes
/
Copy pathFloyd.cpp
File metadata and controls
51 lines (42 loc) · 764 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
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN = 1e6;
int dis[105][105];
int main()
{
int n, m, a, b, c;
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++)
{
fill(dis[i], dis[i] + n + 1, MAXN);
dis[i][i] = 0;
}
while(m --)
{
scanf("%d %d %d", &a, &b, &c);
dis[a][b] = min(dis[a][b], c);
dis[b][a] = min(dis[b][a], c);
}
for(int k = 1; k <= n; k++)
{
for(int i = 1; i <= n; i++)
{
if(i == k) continue;
for(int j = 1; j <= n; j++)
{
if(i == j || k == j) continue;
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j<= n; j++)
printf("%d ", dis[i][j]);
printf("\n");
}
return 0;
}