MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / check_negative_cycle

Function check_negative_cycle

graphs/bellman_ford.py:10–17  ·  view source on GitHub ↗
(
    graph: list[dict[str, int]], distance: list[float], edge_count: int
)

Source from the content-addressed store, hash-verified

8
9
10def check_negative_cycle(
11 graph: list[dict[str, int]], distance: list[float], edge_count: int
12):
13 for j in range(edge_count):
14 u, v, w = (graph[j][k] for k in ["src", "dst", "weight"])
15 if distance[u] != float("inf") and distance[u] + w < distance[v]:
16 return True
17 return False
18
19
20def bellman_ford(

Callers 1

bellman_fordFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected