atcoder#ABC164E. [ABC164E] Two Currencies
[ABC164E] Two Currencies
Score : points
Problem Statement
There are cities numbered to , connected by railroads.
You are now at City , with gold coins and silver coins in your pocket.
The -th railroad connects City and City bidirectionally, and a one-way trip costs silver coins and takes minutes. You cannot use gold coins to pay the fare.
There is an exchange counter in each city. At the exchange counter in City , you can get silver coins for gold coin. The transaction takes minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter.
For each , find the minimum time needed to travel from City to City . You can ignore the time spent waiting for trains.
Constraints
- There is no pair such that .
- Each city can be reached from City with some number of railroads.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
For each in this order, print a line containing the minimum time needed to travel from City to City .
3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5
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 of the city ( for City )
- The second line: /
Similarly, each railroad is labeled as follows:
- The first line: the ID number of the railroad ( for the -th railroad in input)
- The second line: /
You can travel from City to City in minutes, as follows:
- Use the -st railroad to move from City to City in minutes.
You can travel from City to City in minutes, as follows:
- Use the -st railroad to move from City to City in minutes.
- At the exchange counter in City , exchange gold coins for silver coins in minutes.
- Use the -st railroad to move from City to City in minutes.
- Use the -nd railroad to move from City to City in minutes.
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
5
5
7
The railway network in this input is shown in the figure below:
You can travel from City to City in minutes, as follows:
- At the exchange counter in City , exchange gold coins for silver coins in minutes.
- Use the -nd railroad to move from City to City in minutes.
- Use the -th railroad to move from City to City in minutes.
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
1
9003
14606
16510
16576
The railway network in this input is shown in the figure below:
You can travel from City to City in minutes, as follows:
- Use the -st railroad to move from City to City in minute.
- At the exchange counter in City , exchange gold coins for silver coins in minutes.
- Use the -st railroad to move from City to City in minute.
- Use the -nd railroad to move from City to City in minute.
- At the exchange counter in City , exchange gold coins for silver coins in minutes.
- Use the -nd railroad to move from City to City in minute.
- Use the -st railroad to move from City to City in minute.
- Use the -rd railroad to move from City to City in minute.
- At the exchange counter in City , exchange gold coins for silver coins in minutes.
- Use the -rd railroad to move from City to City in minute.
- Use the -st railroad to move from City to City in minute.
- Use the -nd railroad to move from City to City in minute.
- Use the -th railroad to move from City to City in minute.
- At the exchange counter in City , exchange gold coins for silver coins in minutes.
- Use the -th railroad to move from City to City in minute.
- Use the -nd railroad to move from City to City in minute.
- Use the -th railroad to move from City to City in minute.
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
1
3
5
The railway network in this input is shown in the figure below:
2 1 0
1 2 1 1
1 1000000000
1 1
1000000001
The railway network in this input is shown in the figure below:
You can travel from City to City in minutes, as follows:
- At the exchange counter in City , exchange gold coin for silver coin in minutes.
- Use the -st railroad to move from City to City in minute.