#P9329. [JOIST 2023] 两种货币 / Two Currencies
[JOIST 2023] 两种货币 / Two Currencies
Description
There are cities in JOI Kingdom, numbered from to . There are roads in JOI Kingdom, numbered from to . The road connects the city and the city bi-directionally. It is possible to travel from any city to any other city by passing through some of the roads.
There are checkpoints on some of the roads in JOI Kingdom. There are checkpoints, numbered from to . The checkpoint is located on the road . In order to pass through it, you need to pay either one gold coin or silver coins.
There are citizens in JOI Kingdom, numbered from to . The citizen has gold coins and silver coins, and wants to travel from the city to the city . Since gold coins are valuable, all the citizens want to keep as many gold coins as possible.
Write a program which, given information of the cities, the roads, the checkpoints, and the citizens in JOI Kingdom, for each , determines whether it is possible for the citizen to travel from the city to the city , and, if it is possible, calculates the maximum possible number of gold coins the citizen can keep.
Input Format
Read the following data from the standard input.
Output Format
Write lines to the standard output. In the -th line , if the citizen can travel from the city to the city , output the maximum possible number of gold coins the citizen can keep. Otherwise, output in the -th line.
5 4 3
1 2
1 3
2 4
2 5
2 9
2 4
3 5
4 7
3 4 2 11
5 3 4 5
2 3 1 1
1
2
-1
10 7 9
1 8
6 3
5 9
7 9
3 1
3 4
10 1
2 6
5 6
9 4
7 4
7 4
2 4
7 4
7 4
1 4
8 6 5 3
3 9 8 0
4 7 6 15
7 4 9 3
6 4 8 0
9 10 5 16
5 3 2 4
2 8 4 3
6 1 3 3
3
6
6
7
7
3
1
2
2
8 7 11
1 2
2 3
3 4
4 5
5 6
6 7
7 8
4 4
3 7
2 10
5 2
4 1
4 4
5 6
6 3 7 69
7 1 5 55
3 1 6 8
8 2 5 45
4 6 4 45
6 1 3 33
2 1 0 19
3 7 2 31
7 1 2 31
7 2 4 58
8 3 5 63
7
5
5
5
4
2
0
2
1
4
5
8 7 11
1 8
1 4
3 1
3 6
6 7
2 1
5 2
5 5
5 8
4 7
6 6
4 1
6 4
1 7
4 7 2 18
2 4 5 1
4 2 1 32
1 5 7 21
2 5 0 50
8 4 4 33
1 7 6 16
4 8 7 18
1 2 8 13
5 4 10 42
7 1 6 40
1
3
1
7
0
4
5
7
8
10
6
Hint
【样例解释 #1】
The citizen can travel from the city to the city as follows. After the travel, the citizen keeps one gold coin.
- The citizen travels from the city to the city by passing through the road . There are the checkpoints on the road . The citizen pays one gold coin at the checkpoint and passes through it, and silver coins at the checkpoint and passes through it, respectively. After that, the citizen keeps one gold coin and silver coins.
- The citizen travels from the city to the city by passing through the road . Since there is no checkpoint on the road , the citizen keeps one gold coin and silver coins.
- The citizen travels from the city to the city by passing through the road . There is the checkpoint on the road . The citizen pays silver coins at the checkpoint and passes through it. After that, the citizen keeps one gold coin and silver coins.
Since it is impossible for the citizen to travel by finally keeping more than or equal to gold coins, output in the first line.
The citizen can travel from the city to the city as follows. After the travel, the citizen keeps two gold coins.
- The citizen travels from the city to the city by passing through the road . There is the checkpoint on the road . The citizen pays one gold coin at the checkpoint and passes through it. After that, the citizen keeps gold coins and silver coins.
- The citizen travels from the city to the city by passing through the road . Since there is no checkpoint on the road , the citizen keeps gold coins and silver coins.
- The citizen travels from the city to the city by passing through the road . On the road , there are the checkpoints . The citizen pays one gold coin at the checkpoint and passes through it, and silver coins at the checkpoint and passes through it, respectively. After that, the citizen keeps gold coins and one silver coin.
Since it is impossible for the citizen to travel by finally keeping more than or equal to gold coins, output in the second line.
Since it is impossible for the citizen to travel from the city to the city , output in the third line.
该样例满足子任务 的限制。
【样例解释 #2】
该样例满足子任务 的限制。
【样例解释 #3】
该样例满足子任务 的限制。
【样例解释 #4】
该样例满足子任务 的限制。
【数据范围】
对于所有测试数据,满足 ,,,,,,,,,保证给定的道路使所有城市连通,保证所有输入均为整数。
| 子任务编号 | 分值 | 限制 |
|---|---|---|
| , | ||
| 无 |
京公网安备 11011102002149号