Competition Day

Find the shortest simple path from F to C, then the shortest simple path different from it, and report their time difference.

Hard8GraphShortest pathGreedyDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

Matt, Nick and Tim share a flat and enter programming competitions together. A big competition is coming up. Matt has just learned C#, so he wants to show off and compete alone against Nick and Tim, who are sure that their combined Fortran 95 skill will beat him.

Nick suggests that on competition day they drive to the venue by a route different from Matt's, to get in his head. So that Matt sees them take a different route, the three leave the flat at the same time. Matt is a step ahead of them: he has already worked out the fastest route from the flat to the venue.

Tim hates to waste petrol on the same scenery, so their route never visits the same junction twice. The road network has NN junctions and MM one-way roads. The time TT in minutes it takes to drive down each road is already known. The flat and the venue are at different junctions.

A route is a sequence of junctions that starts at the flat, ends at the venue, follows one road at each step, and never visits the same junction twice. Matt drives a fastest route. Nick and Tim drive the fastest route among all routes other than Matt's. If two different routes both take the minimum time, Nick and Tim drive the other one and arrive at the same moment as Matt, so the answer is 00.

How many minutes after Matt do Nick and Tim arrive?

Input

The input holds several test cases. The first line of each test case has four integers NN, MM, FF, CC. (2N80002 \le N \le 8000, 1M80001 \le M \le 8000, 1F,CN1 \le F, C \le N, FCF \ne C) NN is the number of junctions, MM is the number of roads, FF is the junction number of the flat and CC is the junction number of the venue.

MM lines follow, each with three integers ii, jj, TT. (1i,jN1 \le i, j \le N, 0<T2×1050 < T \le 2 \times 10^5) They describe a one-way road from junction ii to junction jj that takes TT minutes to drive.

No road connects a junction to itself, and no two roads connect the same pair of junctions in the same direction. There is always at least one route from FF to CC.

The last line of the input is 0 0 0 0 and is not a test case.

Output

Print one line for each test case. Print how many minutes after Matt Nick and Tim arrive. If Matt's route is the only route from the flat to the venue, print Matt wins. instead.