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.
Hard9GraphShortest pathGreedyDFSNo attempts yetTime limit10sMemory limit512 MBThe JAG Kingdom has N cities and M bidirectional roads. The i-th road (ui,vi,ci) connects city ui and city vi and has length ci. One day you, a citizen of the JAG Kingdom, decide to travel from city S to city T. 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 T in the worst case, output -1.
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 N, M, S, and T: N is the number of cities (2≤N≤100,000), M is the number of bidirectional roads (1≤M≤200,000), S is the city you start from (1≤S≤N), and T is the city you want to reach (1≤T≤N, S=T). The following M lines describe the roads. The i-th of these lines contains three integers ui, vi, and ci, meaning that the i-th road connects city ui and city vi (1≤ui,vi≤N, ui=vi) and has length ci (1≤ci≤109). You may assume that every pair of cities is connected when no road is under construction. That is, for every pair of cities x and y there is at least one route from x to y using the given roads. It is also guaranteed that there are no multiple edges, that is, {ui,vi}={uj,vj} for all 1≤i<j≤M.
Output the minimum total length of the route in the worst case. If you cannot reach city T in the worst case, output -1.