Bellman-Ford Shortest Paths
Single-source shortest paths with negative edge weights
Relax edges instead of finalizing vertices
A negative edge can improve a route after another vertex already looked settled, so the greedy guarantee used by Dijkstra no longer applies. Bellman-Ford repeatedly scans every directed edge and relaxes u -> v whenever dist[u] + w < dist[v].
Why V - 1 rounds are enough
A simple shortest path visits at most V - 1 edges. After round k, all shortest paths using at most k edges can be represented by the distance labels. The player highlights each scanned edge and updates the destination badge only when a shorter candidate is found.
Set source A to distance 0 and every other vertex to infinity.
Cost and negative-cycle detection
Scanning every edge for V - 1 rounds costs O(VE) time and O(V) distance storage. Run one additional round to detect a reachable negative cycle: if any distance still improves, no finite shortest path exists for vertices reachable from that cycle.