Why it matters
APSP with negatives is common need. Johnson's is optimal for sparse. Understanding shapes graph algorithms.
Advertisement
The architecture
Reweight via Bellman-Ford: eliminates negatives.
Dijkstra from each vertex on reweighted graph.
Advertisement
How it works end to end
Reweighting: w'(u,v) = w(u,v) + h(u) - h(v). h from Bellman-Ford from added source.
Preserves shortest paths.
Dijkstra runs O(V(E + V log V)) total.
Recovery: subtract h difference back.