Bellman–Ford and Negative Cycles

hard
Unit 22 · Graphs III0/1 to milestone

Dijkstra fails with negative edge weights (rebates, arbitrage, energy gains). Bellman–Ford handles them: relax every edge n−1n - 1 times. If any edge can still be relaxed after that, there's a negative cycle reachable from the source.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Bellman–Ford and Negative Cycles · TechGradify