File tree 1 file changed +5
-7
lines changed
1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change 12
12
Wiki page:- <https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm>
13
13
"""
14
14
15
-
16
- def floyd_warshall (graph , n ):
15
+ def floyd_warshall (graph : list [list ], num_nodes : int ) -> list [list ]:
17
16
"""
18
17
Returns the shortest distance between all pairs of nodes
19
18
@@ -37,14 +36,13 @@ def floyd_warshall(graph, n):
37
36
"""
38
37
# The graph is a Adjancecy matrix (see <https://en.wikipedia.org/wiki/Adjacency_matrix>)
39
38
distance : list [list ] = graph
40
- for k in range (n ):
41
- for i in range (n ):
42
- for j in range (n ):
39
+ for k in range (num_nodes ):
40
+ for i in range (num_nodes ):
41
+ for j in range (num_nodes ):
43
42
distance [i ][j ] = min (distance [i ][j ], distance [i ][k ] + distance [k ][j ])
44
43
return distance
45
44
46
-
47
- if __name__ == "__main__" :
45
+ if __name__ == '__main__' :
48
46
"""
49
47
Layout of G:-
50
48
2 2 1 1 5
You can’t perform that action at this time.
0 commit comments