mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 17:34:49 +08:00
Fix bug in bellman_ford.py (#1544)
This commit is contained in:
@ -13,14 +13,14 @@ def BellmanFord(graph, V, E, src):
|
|||||||
mdist[src] = 0.0
|
mdist[src] = 0.0
|
||||||
|
|
||||||
for i in range(V - 1):
|
for i in range(V - 1):
|
||||||
for j in range(V):
|
for j in range(E):
|
||||||
u = graph[j]["src"]
|
u = graph[j]["src"]
|
||||||
v = graph[j]["dst"]
|
v = graph[j]["dst"]
|
||||||
w = graph[j]["weight"]
|
w = graph[j]["weight"]
|
||||||
|
|
||||||
if mdist[u] != float("inf") and mdist[u] + w < mdist[v]:
|
if mdist[u] != float("inf") and mdist[u] + w < mdist[v]:
|
||||||
mdist[v] = mdist[u] + w
|
mdist[v] = mdist[u] + w
|
||||||
for j in range(V):
|
for j in range(E):
|
||||||
u = graph[j]["src"]
|
u = graph[j]["src"]
|
||||||
v = graph[j]["dst"]
|
v = graph[j]["dst"]
|
||||||
w = graph[j]["weight"]
|
w = graph[j]["weight"]
|
||||||
|
Reference in New Issue
Block a user