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