Revenge of the Broken Door
Time limit10sMemory limit512 MB
An adversary hides one edge under construction; the traveler learns about an edge only upon reaching its endpoint and must minimize the worst-case distance from S to T.
- Level
Hard9 of 10
- Topics
- Graph, Shortest path, Greedy, DFS
- Solved
- No attempts yet
Problem
The JAG Kingdom has cities and bidirectional roads. The -th road connects city and city and has length . One day you, a citizen of the JAG Kingdom, decide to travel from city to city . You know that one road in the kingdom is currently under construction and cannot be passed, but you do not know which road it is. You can find out whether a road is under construction only while you are in one of the two cities that the road connects.
Minimize the total length of your route in the worst case. You do not have to fix a route before departure, and you may decide where to go next at any time. If you cannot reach city in the worst case, output -1.
Input
The input consists of a single test case in the following format.
N M S T
u1 v1 c1
.
.
.
uM vM cM
The first line contains four integers , , , and : is the number of cities (), is the number of bidirectional roads (), is the city you start from (), and is the city you want to reach (, ). The following lines describe the roads. The -th of these lines contains three integers , , and , meaning that the -th road connects city and city (, ) and has length (). You may assume that every pair of cities is connected when no road is under construction. That is, for every pair of cities and there is at least one route from to using the given roads. It is also guaranteed that there are no multiple edges, that is, for all .
Output
Output the minimum total length of the route in the worst case. If you cannot reach city in the worst case, output -1.