The National University of Singapore is built on a hill, so even if the distance from A to B seems short from the map, walking over the steep ladder is very exhausting. Fortunately, there's a shuttle bus service.
Suppose that NUS has buildings and bidirectional roads. A shuttle bus starts moving from building X to building Y (the detailed path will be given). At the same time, Chris starts walking from building A and wants to go to building B. Chris is as fast as the shuttle bus, but walking meters requires amount of energy (in Joules) while no energy is spent if he travels by a shuttle bus. What is the minimum amount of energy will Chris need to arrive at his destination?
Details and Assumptions
Input Format
The first line consists of two integers
,
- the number of buildings and the number of bidirectional roads.
The next
lines each contains 3 integers
describing a bidirectional road connecting building
and
of length
.
The next line contains an integer
, the number of buildings the shuttle bus go through.
The next line contains
integers, describing the path of the shuttle bus in that order.
The last line contains two integers
and
, the starting building and the destination respectively.
Sample Input
1 2 3 4 5 6 7 8 9 |
|
Sample Output
1 |
|
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
We can interpret this as a undirected wheighted graph in which the wheight of the nodes connected by the bus is 0, from there we can simply run dijkstra's shortest path algorithm and we get the result. Here is my c++11 implementation.