Let P=(v0,v1,v2,…,vk) be any directed path from vertex u=v0 to vertex v=vk.
The total weight of path P under the modified weight function w′ is given by the telescoping sum:
w′(P)=i=1∑kw′(vi−1,vi)=i=1∑k[w(vi−1,vi)+f(vi−1)−f(vi)] w′(P)=i=1∑kw(vi−1,vi)+[f(v0)−f(v1)+f(v1)−f(v2)+⋯+f(vk−1)−f(vk)] w′(P)=w(P)+f(u)−f(v) Notice that the extra term f(u)−f(v) depends solely on the source u and target v, and is identical for all paths between u and v. Adding a constant value to every path between u and v does not change their relative ordering in weight.
Therefore, a path between u and v minimizes w(P) if and only if it minimizes w′(P). This property holds for every function f:V→R, making A the correct choice (this is the reweighting technique used in Johnson's algorithm).