forked from DanielW48/HackPack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFloyd.java
More file actions
24 lines (22 loc) · 683 Bytes
/
Floyd.java
File metadata and controls
24 lines (22 loc) · 683 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
class Floyd {
static int n, m;
static long inf = Long.MAX_VALUE / 2;
static long[][] d;
public static void main (String[] args){
d = new long[n][n];
for(int i = 0; i < n; ++i) Arrays.fill(d[i], inf);
for(int i = 0; i < n; ++i) d[i][i] = 0;
//edges of graph
for(int i = 0; i < m; ++i){
int a, b, w;
if(w < d[a][b]) d[a][b] = d[b][a] = w;
}
for(int k = 0; k < n; ++k){
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
}
}
}
}
}