Revenge of the Broken Door

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 MB

Problem

The JAG Kingdom has NN cities and MM bidirectional roads. The ii-th road (ui,vi,ci)(u_i, v_i, c_i) connects city uiu_i and city viv_i and has length cic_i. One day you, a citizen of the JAG Kingdom, decide to travel from city SS to city TT. 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 TT 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 NN, MM, SS, and TT: NN is the number of cities (2N100,0002 \le N \le 100{,}000), MM is the number of bidirectional roads (1M200,0001 \le M \le 200{,}000), SS is the city you start from (1SN1 \le S \le N), and TT is the city you want to reach (1TN1 \le T \le N, STS \ne T). The following MM lines describe the roads. The ii-th of these lines contains three integers uiu_i, viv_i, and cic_i, meaning that the ii-th road connects city uiu_i and city viv_i (1ui,viN1 \le u_i, v_i \le N, uiviu_i \ne v_i) and has length cic_i (1ci1091 \le c_i \le 10^9). You may assume that every pair of cities is connected when no road is under construction. That is, for every pair of cities xx and yy there is at least one route from xx to yy using the given roads. It is also guaranteed that there are no multiple edges, that is, {ui,vi}{uj,vj}\{u_i, v_i\} \ne \{u_j, v_j\} for all 1i<jM1 \le i < j \le M.

Output

Output the minimum total length of the route in the worst case. If you cannot reach city TT in the worst case, output -1.