Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 42s1 days 16 hours 1 minutes 42 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 42s1 days 16 hours 1 minutes 42 seconds.

Sign in to watch this lesson
Advanced - Graphs · 4:32
A currency loop whose rates multiply to more than one becomes a negative cycle once every rate r is turned into the weight −log r. Starting every Bellman–Ford label at zero (a virtual source joined to every vertex) finds a negative cycle anywhere in the graph, and n parent steps from the last relaxed vertex land on the loop before we collect it. For all pairs, Floyd–Warshall marks (i, j) as −∞ when i reaches a vertex with a negative distance to itself that reaches j, and Johnson's potentials make every weight non-negative for Dijkstra.