Reweighting
Intuition: if we convert the edge weight to be positive, then we can use Dijkstra’s Algorithm on all vertexes to compute all pair shortest path.
Reweighting cannot change the shortest path for any vertex . That is, the shortest path between any must remain unchange after reweighting. Second, reweighting must preserve negative cycle.
, for all edge , define , where is the shortest path from a super external source which connects to evert vertexes (or any vertex that reaches every other vertexes), as the graph shows.
source : wiki
Correctness
Consider vertex , is the shortest path length from , then by the definition of shortest path, we know
For a shortest path ,
proof the shortest path property unchanged by contradiction
Assume that there is another shortest path , with . Then , which is a contradiction, because is the original shortest path, there is no way other path length would be shorter than that.
Proof of negative cycle preservation after reweighting
For this cycle ,