View problem - Price List (POI13_cen)

Time limitMemory limit# of submissions# of submitted usersSolved #Accepted user ratio
4000 ms64 MiB123161593.75%

Railway has always been the most popular mean of transport in Byteotia. Out of nn towns in the land, mm pairs are connected by track segments belonging to Byteotian State Railways (BSR). The tracks do not cross outside of towns, and may lead through picturesque bridges and somewhat less picturesque tunnels. The ticket for travelling between any two towns directly connected by rail costs aa bythalers.

Currently the transportation market in Byteotia is changing. As of now, BSR faces a new competitor: Byteotian Airlines (BA). BA plans to operate flights between some pairs of towns. Since Byteotian railways are quite comfortable, the BA board has decided to operate flights only between pairs of towns that are not directly connected by rail. Due to economy, BA will fly only between towns for which the cheapest railway connection requires exactly one change. The ticket for each such flight is going to cost bb bythalers.

To help Byteotian citizens in planning their trips, the Byteotian Ministry for Transport (BMT) has decided to issue leaflets specifying the cheapest routes between all possible towns. A sequence of an arbitrary number of direct railway or airplane connections is called a route. A BMT officer by the name of Byteasar has been commissioned with the task of preparing the price list for the leaflets. Could you help him in writing a program that will determine the right prices?

Let us clarify that all the connections in Byteotia, both by railway and airplane, are bidirectional.

Input

The first line of the standard input contains five integers, nn, mm, kk, aa, and bb (2n100,0002 \le n \le 100,000, 1m100,0001 \le m \le 100,000, 1kn1 \le k \le n, 1a,b1,0001 \le a,b \le 1,000), separated by single spaces. The numbers nn and mm denote the number of towns and the number of direct railway connections in Byteotia, respectively. For simplicity, we number the towns in Byteotia from 11 to nn. The other numbers denote: kk - the number of the source town for which the connection prices are to be determined; aa - the price of a direct railway connection; bb - the price of a direct airplane connection.

Each of the following mm lines contains a pair of integers uiu_i and viv_i (1ui,vin1 \le u_i, v_i \le n, uiviu_i \neq v_i for i=1,2,,mi=1,2,\cdots,m), separated by a single space, specifying the number of towns directly connected by tracks.

You may assume that all towns are reachable by railway from the town no. kk.

In tests worth 30% of all points the conditions n700n \le 700 and m700m \le 700 hold in addition.

Output

Your program should print nn lines to the standard output. The line no. ii(for i=1,2,,ni=1,2,\cdots,n) should contain a single integer: the cost of the cheapest route from town no. kk to town no. ii. Among those, the line no. kk should contain the number 00.

Example

for the input data:

5 5 1 3 2
1 2
2 3
3 4
4 5
3 1

the correct result is:

0
3
3
2
5

Explanation of the example: The cheapest route from town no. 1 to town no. 5 leads through either town no. 3 or town no. 4. In both cases it consists of a single railway link and a single airplane link.