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 nn vertices and mm edges. There are KK guards protecting the mine. The ii-th guard stays at vertex PiP_i.

You have stolen xx kilograms of uranium, and you plan to choose a path to move from vertex SS to vertex TT. If x>0x>0, then during the transfer, you must ensure that at any moment, your distance to every guard is greater than xx. Otherwise, you will be discovered.

Obviously, you will not steal only once. You need to steal uranium QQ times. Each time, given SS and TT, ask for the maximum number of kilograms of uranium you can steal.

Input Format

The first line contains two integers n,mn,m.

The next mm lines each contain three integers x,y,zx,y,z, meaning there is an undirected edge of length zz between xx and yy.

The next line contains an integer KK. The following line contains KK integers PiP_i.

Then comes a positive integer QQ. The next QQ lines each contain two integers S,TS,T.

Output Format

Output QQ lines, each containing one integer as the answer. If it is impossible to complete the theft task, output 00.

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 100%100\% of the testdata, it is guaranteed that 1n,K,Q1051\leq n,K,Q\leq 10^5, 1m2×1051\leq m\leq 2\times 10^5, 1x,y,Pin1\leq x,y,P_i\leq n, 1z1091\leq z\leq 10^9, and STS\neq T.

Notes

Translated from AGM 2022 Qualification Round L Uranium

Translated by ChatGPT 5