luogu#P9329. [JOISC 2023 Day1] Two Currencies
[JOISC 2023 Day1] Two Currencies
题目描述
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.
输入格式
Read the following data from the standard input.
输出格式
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.
题目大意
题目描述
在 JOI 王国中,有 个城市,编号从 到 。JOI 王国有 条双向道路,编号从 到 。第 条道路连接城市 和城市 。
在 JOI 王国中,一些道路上放有检查站。有 个检查站,编号从 到 。第 个检查站位于道路 上。通过该检查站需要支付 枚金币或 枚银币。
在 JOI 王国有 名公民,编号从 到 。第 名公民持有 枚金币和 枚银币,并希望从城市 前往城市 。由于金币具有较高的价值,所有公民都希望尽可能多地保留金币。
编写一个程序,给定 JOI 王国中的城市、道路、检查站和公民信息,对于每个 ,判断公民 是否能够从城市 前往城市 ,并在此条件成立时计算公民 所能保留的最多金币数。
输入格式
从标准输入读入以下数据。
输出格式
向标准输出打印 行。在第 行 中,如果公民 可以从城市 前往城市 ,请输出公民 可以保留的最多金币数。否则,在第 行中输出 。
Translate by
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
提示
【样例解释 #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】
该样例满足子任务 的限制。
【数据范围】
对于所有测试数据,满足 ,,,,,,,,,保证给定的道路使所有城市连通,保证所有输入均为整数。
子任务编号 | 分值 | 限制 |
---|---|---|
, | ||
无 |