luogu#P8063. [BalkanOI 2012] Shortest paths
[BalkanOI 2012] Shortest paths
Background
You in Bit Town are going to Hex Town to meet your npy.
Problem Description
There are towns in your country (numbered from to ) and bidirectional roads. Bit Town is at node , and Hex Town is at node . Each road has a length. Since you know the map very well, you have found the shortest path between the two towns, and you decide to call this path the lucky path.
One day, the government decides to do construction on the roads. To keep traffic running, they decide to close only one road at a time (a closed road cannot be used).
For every road on this lucky path, you want to know the shortest distance from Bit Town to Hex Town when that road is closed.
Input Format
The first line contains 4 integers: , representing the number of towns, the number of roads, the index of Bit Town, and the index of Hex Town.
The next lines describe the roads. The -th line contains three integers : towns and are connected by a road of length .
The last line contains a number and numbers: , describing the lucky path. is the index of the -th node on the lucky path.
Output Format
Output lines in total.
For each , output one integer on one line: when the road is under construction (closed), the length of the shortest path between Bit Town and Hex Town. If the path does not exist, output -1.
5 6 1 5
1 2 1
2 3 3
2 5 100
3 4 3
3 5 5
4 5 3
4 1 2 3 5
-1
101
10
Hint
Constraints
Subtask#0 is the sample.
,,,。
For , it holds that or .
Sample Explanation

After closing road , Bit Town at node cannot reach Hex Town at node .
After closing road , the shortest path from Bit Town at node to Hex Town at node is , with length .
After closing road , the shortest path from Bit Town at node to Hex Town at node is , with length 。
Translated by ChatGPT 5