Shortest Paths
Time limit1sMemory limit128 MB
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 , , , : is the number of towns, is the number of roads, is the number of the town of Bit (where Nikola lives), and is the number of the town of Hex (where Anita lives).
The towns are numbered from to . Each of the next lines contains three integers , , , meaning that town and town are connected by a road of length .
The last line contains an integer followed by town numbers (with and ), describing Nikola's lucky route.
Output
For each , print on its own line the length of the shortest route from town to town when road is closed. If no such route exists, print .
Constraints
- ,
- There is at most one road between any two distinct towns.
- The given lucky route is one of the shortest routes from town to town .
Hint
