luogu#P8240. [AGM 2022 资格赛] 偷铀计划
[AGM 2022 资格赛] 偷铀计划
Problem Description
You are a thief. You decide to steal some uranium so that you can grow bigger quickly in the game Digdig.io.
You have a map. This mine is an undirected graph with vertices and edges. There are guards protecting the mine. The -th guard stays at vertex .
You have stolen kilograms of uranium, and you plan to choose a path to move from vertex to vertex . If , then during the transfer, you must ensure that at any moment, your distance to every guard is greater than . Otherwise, you will be discovered.
Obviously, you will not steal only once. You need to steal uranium times. Each time, given and , ask for the maximum number of kilograms of uranium you can steal.
Input Format
The first line contains two integers .
The next lines each contain three integers , meaning there is an undirected edge of length between and .
The next line contains an integer . The following line contains integers .
Then comes a positive integer . The next lines each contain two integers .
Output Format
Output lines, each containing one integer as the answer. If it is impossible to complete the theft task, output .
5 6
1 2 1
2 3 3
3 4 3
2 4 4
1 5 1
4 5 1
1
2
3
1 3
5 3
4 3
0
1
2
9 10
1 2 1
2 3 4
2 4 2
4 5 5
5 9 10
5 6 10
6 7 2
6 9 5
9 8 8
8 7 3
2
4 9
5
1 3
1 6
5 7
6 9
7 8
1
0
4
0
6
Hint
Constraints
For of the testdata, it is guaranteed that , , , , and .
Notes
Translated from AGM 2022 Qualification Round L Uranium。
Translated by ChatGPT 5