The following is the question I am working on:
Consider a directed, weighted graph G where all edge weights are positive. The goal of this problem is to find the shortest path in G between two pre-specified vertices s and t , but with an added twist: you are allowed to change the weight of exactly one edge (of your choosing) to zero.
In other words, you must pick an edge in G to set to zero that minimizes the shortest path between s and t . Give an efficient algorithm to achieve this goal in O ( E lg V ) time and analyze your algorithm’s running time. Sub-optimal solutions will receive less credit.
Hint: You may have to reverse the edges, run a familiar algorithm a number of times, plus do some extra work
So I have tried running Dijkstra's from s to all other nodes and then I have tried reversing the edges and running it again from s to all other nodes. However, I found out that we have to run Dijskstra's from s to all other nodes and then reverse the edges and then run Dijkstra's from all other nodes to t. I am not exactly sure how this helps us to find the edge to set to zero. By my intuition I thought that we would simply set the maximum weight edge to zero. What is the point of reversing the edges?
We need to run Dijkstra's algorithm twice - once for the original graph with
sas the source vertex, and once with the reversed graph andtas the source vertex. We'll denote the distance we get between vertexsandifrom the first run asD(i)and the distance we get between vertextandisecond runD_rev(i).Note that we can go follow the reversed edges backwards (i.e., follow them in the original direction), thus
D_rev(i)is actually the shortest distance from vertexitot. Similarly,D(i)is the shortest distance from vertexstoifollowing Dijkstra's algorithm.We can now loop through all the edges, and for each edge
ewhich connectsv1andv2, add upD(v1)andD_rev(v2), which corresponds to the weight of the paths -> v1 -> v2 -> twithebeing the zero edge, since we can go fromstov1with a distance ofD(v1), seteto 0, go fromv1tov2, and then go fromv2totwith a distance ofD_rev(v2). The minimum over these is the answer.A rough proof sketch (and also a restatement) : if we set an edge
eto 0, but don't use it in the path, we can be better off setting an edge that's in the path to 0. Thus, we need only consider paths that includes the zeroed edge. The shortest path through a zeroed edgeeis to first take the shortest path fromstov1, and then take the shortest path fromv2tot, which are exactly what were computed using the Dijkstra algorithm, i.e.,DandD_rev.Hope this answer helps!