Shortest Paths

Time limit1sMemory limit128 MB

Summary
For each edge on a given shortest a-b path, report the length of the shortest a-b route that avoids that edge.
Level

Hard8 of 10

Topics
Shortest path, Graph, Divide and conquer, Dynamic programming
Solved
No attempts yet

Problem

Nikola lives in the town of Bit and is dating Anita, who lives in the town of Hex. Nikola knows the surrounding map so well that he has found one shortest route between the two towns, which he calls the lucky route. The map is given as a set of bidirectional roads connecting distinct towns.

One day the president decides to carry out roadworks. To keep the country's traffic flowing, exactly one road is closed each day.

For each road on the lucky route, Nikola wants to know the length of the shortest route from his town to Anita's town when that road is closed.

Input

The first line contains four integers nn, mm, aa, bb: nn is the number of towns, mm is the number of roads, aa is the number of the town of Bit (where Nikola lives), and bb is the number of the town of Hex (where Anita lives).

The towns are numbered from 11 to nn. Each of the next mm lines contains three integers uu, vv, ww, meaning that town uu and town vv are connected by a road of length ww.

The last line contains an integer kk followed by kk town numbers v1,v2,…,vkv_1, v_2, \ldots, v_k (with v1=av_1 = a and vk=bv_k = b), describing Nikola's lucky route.

Output

For each t=1,2,…,k−1t = 1, 2, \ldots, k-1, print on its own line the length of the shortest route from town aa to town bb when road (vt,vt+1)(v_t, v_{t+1}) is closed. If no such route exists, print −1-1.

Constraints

  • 1≤n≤20001 \le n \le 2000, 1≤m≤1000001 \le m \le 100000
  • 1≤a,b≤n1 \le a, b \le n
  • 1≤w≤1000001 \le w \le 100000
  • There is at most one road between any two distinct towns.
  • The given lucky route is one of the shortest routes from town aa to town bb.

Hint

Examples3

  1. Example 1

    Input
    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
    
    Expected output
    -1
    101
    10
    
  2. Example 2

    Input
    3 3 1 3
    1 2 1
    2 3 1
    1 3 5
    3 1 2 3
    
    Expected output
    5
    5
    
  3. Example 3

    Input
    4 4 1 4
    1 2 1
    2 3 1
    3 4 1
    2 4 5
    4 1 2 3 4
    
    Expected output
    -1
    6
    6