Step through edge relaxation in a directed weighted graph — handles negative weights and detects negative cycles. Run all at once or advance one edge at a time.
if dist[u] + w(u,v) < dist[v]: dist[v] = dist[u] + w(u,v)
Bellman-Ford solves the single-source shortest path problem on directed graphs with negative-weight edges — where Dijkstra fails. The key idea: relax every edge |V|−1 times.
After |V|−1 iterations, an extra pass that still finds an improvement signals a negative cycle — a cycle whose total weight is negative, making "shortest path" undefined.
One-on-one tutoring in graph algorithms, dynamic programming, and discrete math — from Bellman-Ford through network flows.