#abc164e. [abc164_e]Two Currencies

[abc164_e]Two Currencies

Problem Statement

There are NN cities numbered 11 to NN, connected by MM railroads.

You are now at City 11, with 1010010^{100} gold coins and SS silver coins in your pocket.

The ii-th railroad connects City UiU_i and City ViV_i bidirectionally, and a one-way trip costs AiA_i silver coins and takes BiB_i minutes. You cannot use gold coins to pay the fare.

There is an exchange counter in each city. At the exchange counter in City ii, you can get CiC_i silver coins for 11 gold coin. The transaction takes DiD_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter.

For each t=2,...,Nt=2, ..., N, find the minimum time needed to travel from City 11 to City tt. You can ignore the time spent waiting for trains.

Constraints

  • 2leqNleq502 \\leq N \\leq 50
  • N1leqMleq100N-1 \\leq M \\leq 100
  • 0leqSleq1090 \\leq S \\leq 10^9
  • 1leqAileq501 \\leq A_i \\leq 50
  • 1leqBi,Ci,Dileq1091 \\leq B_i,C_i,D_i \\leq 10^9
  • 1leqUi<VileqN1 \\leq U_i < V_i \\leq N
  • There is no pair i,j(ineqj)i, j(i \\neq j) such that (Ui,Vi)=(Uj,Vj)(U_i,V_i)=(U_j,V_j).
  • Each city t=2,...,Nt=2,...,N can be reached from City 11 with some number of railroads.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM SS U1U_1 V1V_1 A1A_1 B1B_1 :: UMU_M VMV_M AMA_M BMB_M C1C_1 D1D_1 :: CNC_N DND_N

Output

For each t=2,...,Nt=2, ..., N in this order, print a line containing the minimum time needed to travel from City 11 to City tt.


Sample Input 1

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

Sample Output 1

2
14

The railway network in this input is shown in the figure below.

In this figure, each city is labeled as follows:

  • The first line: the ID number ii of the city (ii for City ii)
  • The second line: CiC_i / DiD_i

Similarly, each railroad is labeled as follows:

  • The first line: the ID number ii of the railroad (ii for the ii-th railroad in input)
  • The second line: AiA_i / BiB_i

Figure

You can travel from City 11 to City 22 in 22 minutes, as follows:

  • Use the 11-st railroad to move from City 11 to City 22 in 22 minutes.

You can travel from City 11 to City 33 in 1414 minutes, as follows:

  • Use the 11-st railroad to move from City 11 to City 22 in 22 minutes.
  • At the exchange counter in City 22, exchange 33 gold coins for 33 silver coins in 66 minutes.
  • Use the 11-st railroad to move from City 22 to City 11 in 22 minutes.
  • Use the 22-nd railroad to move from City 11 to City 33 in 44 minutes.

Sample Input 2

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

Sample Output 2

5
5
7

The railway network in this input is shown in the figure below:

Figure

You can travel from City 11 to City 44 in 77 minutes, as follows:

  • At the exchange counter in City 11, exchange 22 gold coins for 66 silver coins in 22 minutes.
  • Use the 22-nd railroad to move from City 11 to City 33 in 44 minutes.
  • Use the 44-th railroad to move from City 33 to City 44 in 11 minutes.

Sample Input 3

6 5 1
1 2 1 1
1 3 2 1
2 4 5 1
3 5 11 1
1 6 50 1
1 10000
1 3000
1 700
1 100
1 1
100 1

Sample Output 3

1
9003
14606
16510
16576

The railway network in this input is shown in the figure below:

Figure

You can travel from City 11 to City 66 in 1657616576 minutes, as follows:

  • Use the 11-st railroad to move from City 11 to City 22 in 11 minute.
  • At the exchange counter in City 22, exchange 33 gold coins for 33 silver coins in 90009000 minutes.
  • Use the 11-st railroad to move from City 22 to City 11 in 11 minute.
  • Use the 22-nd railroad to move from City 11 to City 33 in 11 minute.
  • At the exchange counter in City 33, exchange 88 gold coins for 88 silver coins in 56005600 minutes.
  • Use the 22-nd railroad to move from City 33 to City 11 in 11 minute.
  • Use the 11-st railroad to move from City 11 to City 22 in 11 minute.
  • Use the 33-rd railroad to move from City 22 to City 44 in 11 minute.
  • At the exchange counter in City 44, exchange 1919 gold coins for 1919 silver coins in 19001900 minutes.
  • Use the 33-rd railroad to move from City 44 to City 22 in 11 minute.
  • Use the 11-st railroad to move from City 22 to City 11 in 11 minute.
  • Use the 22-nd railroad to move from City 11 to City 33 in 11 minute.
  • Use the 44-th railroad to move from City 33 to City 55 in 11 minute.
  • At the exchange counter in City 55, exchange 6363 gold coins for 6363 silver coins in 6363 minutes.
  • Use the 44-th railroad to move from City 55 to City 33 in 11 minute.
  • Use the 22-nd railroad to move from City 33 to City 11 in 11 minute.
  • Use the 55-th railroad to move from City 11 to City 66 in 11 minute.

Sample Input 4

4 6 1000000000
1 2 50 1
1 3 50 5
1 4 50 7
2 3 50 2
2 4 50 4
3 4 50 3
10 2
4 4
5 5
7 7

Sample Output 4

1
3
5

The railway network in this input is shown in the figure below:

Figure


Sample Input 5

2 1 0
1 2 1 1
1 1000000000
1 1

Sample Output 5

1000000001

The railway network in this input is shown in the figure below:

Figure

You can travel from City 11 to City 22 in 10000000011000000001 minutes, as follows:

  • At the exchange counter in City 11, exchange 11 gold coin for 11 silver coin in 10000000001000000000 minutes.
  • Use the 11-st railroad to move from City 11 to City 22 in 11 minute.