Weekly Meeting
InterviewTime limit1sMemory limit512 MB
For each member's house, add the shortest distances to two fixed nodes and sum all results, counting unreachable as -1.
- Level
Medium4 of 10
- Topics
- Shortest path, Graph, Heap
- Solved
- No attempts yet
Problem
If you are picked for the second class of the KIST Knights, the team gathers at KIST in Wolgok, Seoul and at CR Food in Yangjae to talk things over and work together. Everyone wants to reach the meeting place quickly.
Treat each place as a node and each road as an edge, and you get a graph. You are given the node number of the house of each of the members, together with the node numbers of KIST and CR Food. The distance of the th member is defined as (shortest distance from the house to KIST) + (shortest distance from the house to CR Food). A shortest distance to a place that cannot be reached is defined as . For example, a member who cannot reach KIST and whose shortest distance to CR Food is 10 has distance , and a member who can reach neither KIST nor CR Food has distance .
Write a program that prints the value of .
Input
The first line contains the number of KIST Knights members , the number of places , and the number of roads . (1 ≤ ≤ 100, 1 ≤ ≤ 1000, 0 ≤ ≤ 10000)
The second line contains the location of KIST and the location of CR Food. (1 ≤ , ≤ )
The third line contains the house locations of the members, separated by spaces. (1 ≤ ≤ , 1 ≤ ≤ )
Each of the next lines contains the two endpoints , of a road and its length . (1 ≤ , ≤ , 1 ≤ ≤ 100) A road can be travelled in both directions. Several roads may join the same two places, and a road with equal to may appear.
Output
Print the sum of the distances of all members on one line. A shortest distance to KIST or to CR Food that cannot be reached counts as .