Loading...
Single-source shortest paths in graphs with negative weights.
Works with w < 0
Sequential relaxations
Detects negatives
Initialize dist[source]=0 and all others to ∞. Repeatedly relax every edge (u,v,w): if dist[u] + w < dist[v], update dist[v]. After |V|−1 passes, all shortest paths (with at most |V|−1 edges) are found. A final pass that still improves some dist[v] reveals a negative weight cycle reachable from the source.