I am stuck on this problem. https://www.codechef.com/problems/IOPC16K
Problem Statement:
Find out what will be the new shortest path if one of the edge on the original shortest path is removed.Find for all of the edges in shortest path path(Given Unique original shortest path).
Constraints:
no. of edges <= 1e5
no. of nodes <= 1e5
weights of edges <= 1e9
I Looked at some of the AC solutions but could not get the Idea. So if somebody can share the Idea to solve the problem it would be very Helpful! (I think its on some Algorithmic Paper).
alecsyde, being the setter for the problem, it would be great if you can share the solution for the problem or link to any other similar problem.
Make the shortest distance tree rooted at s, and compute shortest distances from s and t. Let Ti be the subtree rooted at i. Let Ei be the set of the graph edges which connect Ti to V - Ti except the edge connecting i to its parent.
Now, for some ancestor i ≠ s of t, say edge (i, j) is removed such that j is the parent of i in the tree. Consider edges of form , such that . It can be proved that the deletion of edge (i, j) doesn't change the length of the shortest paths from s to v and from t to u (Try to prove it, its not that trivial). Thus, the new shortest path is minimum of d(s, v) + d(t, u) + wu, v over all such edges.
To compute efficiently for all edges in the shortest path, start from i = t move up to reach s in the tree and think about how the set E changes. You'll have to make a linear number of changes in the set overall (each edge would be inserted atmax once and deleted atmax once). Overall complexity is .
Ok. I got The Idea. Just to be Sure, I am restating your idea in my terms.
Thank you for the help and a prompt reply.