Route Detour

Find the cheapest route from a repaired vehicle's city to the destination, where any first contact with the fixed route forces the rest of the trip to follow that route exactly.

Medium6GraphShortest pathGreedyImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

The road system of a country links all of its NN cities, so from any city you can reach every other city over the existing roads. Each road joins two distinct cities, carries traffic in both directions, and has one toll booth. The toll is paid in both directions of travel. Roads meet only at cities. No pair of cities is joined by two or more roads.

Dias Transport runs a parcel delivery service between the cities. Each parcel has to be carried from a city AA to another city BB. For every parcel the company fixes a service route made of CC cities and C1C-1 roads. The first city of the service route is the origin of the parcel and the last one is its destination. The service route never visits the same city twice, and the vehicle assigned to a parcel may drive only along the service route it was given.

One day the vehicle on a delivery broke down. It was taken for repair to a city that is not one of the cities on its service route. The company wants the minimum total toll cost for the vehicle to deliver the parcel to the destination city, starting from the city where it was repaired, under one extra restriction: if at some moment the vehicle passes through one of the cities of its service route, from that city on it must follow the service route again.

Input

The input contains several test cases.

The first line of a test case has four integers NN, MM, CC and KK (4N2504 \le N \le 250, 3MN×(N1)/23 \le M \le N \times (N-1) / 2, 2CN12 \le C \le N-1, CKN1C \le K \le N-1), giving the number of cities in the country, the number of roads, the number of cities on the service route, and the city where the vehicle was repaired. Cities are identified by integers from 00 to N1N-1. The service route is 0,1,,C10, 1, \ldots, C-1: the origin is 00, from 00 it goes to 11, from 11 to 22, and so on up to the destination C1C-1.

The next MM lines describe the road system of the country. Each of those lines describes one road and has three integers UU, VV and PP (0U,VN10 \le U, V \le N-1, UVU \neq V, 0P2500 \le P \le 250), meaning that a road joins cities UU and VV with toll cost PP.

The last test case is followed by a line containing four zeros separated by whitespace.

Output

For each test case print a single line with a single integer TT, the minimum total toll cost for the vehicle to reach the destination.