-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfloyd.cpp
More file actions
36 lines (28 loc) · 692 Bytes
/
floyd.cpp
File metadata and controls
36 lines (28 loc) · 692 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
#include <bits/stdc++.h>
using namespace std;
#define INF (1<<29)
#define N 100
int main(){
int edge[N][N] = {0};
edge[0][1] = 10;
edge[1][2] = 25;
edge[2][3] = 1;
edge[0][2] = 200;
int dist[N][N];
for(int i = 0;i < N;i++){
for(int j = 0;j < N;j++){
if (i == j) dist[i][j] = 0;
else if (edge[i][j]) dist[i][j] = edge[i][j];
else dist[i][j] = INF;
}
}
for(int k = 0;k < N;k++){
for(int i = 0;i < N;i++){
for(int j = 0;j < N;j++){
dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
}
}
}
cout << dist[0][2] << endl;
return 0;
}