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 nn towns in your country (numbered from 11 to nn) and mm bidirectional roads. Bit Town is at node aa, and Hex Town is at node bb. 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: n,m,a,bn,m,a,b, representing the number of towns, the number of roads, the index of Bit Town, and the index of Hex Town.

The next mm lines describe the roads. The ii-th line contains three integers ui,vi,wiu_i,v_i,w_i: towns uiu_i and viv_i are connected by a road of length wiw_i.

The last line contains a number kk and kk numbers: (v1(=a),v2,,vk(=b))(v_1(=a),v_2,\dots,v_{k}(=b)), describing the lucky path. vi(1ik)v_i(1\le i\le k) is the index of the ii-th node on the lucky path.

Output Format

Output k1k-1 lines in total.

For each t=1k1t=1\dots k-1, output one integer on one line: when the road (vt,vt+1)(v_t,v_{t+1}) 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.

1n20001\le n\le 20001m1051\le m\le10^51ui,vin1\le u_i,v_i\le n1wi1051\le w_i\le10^5

For iji\neq j, it holds that uiuju_i\neq u_j or vivjv_i\neq v_j.

Sample Explanation

After closing road (1,2)(1,2), Bit Town at node 11 cannot reach Hex Town at node 55.

After closing road (2,3)(2,3), the shortest path from Bit Town at node 11 to Hex Town at node 55 is 1251\rightarrow 2\rightarrow5, with length 1+100=1011+100=101.

After closing road (3,5)(3,5), the shortest path from Bit Town at node 11 to Hex Town at node 55 is 123451\rightarrow 2\rightarrow3\rightarrow4\rightarrow5, with length 1+3+3+3=101+3+3+3=10

Translated by ChatGPT 5