Baltic Olympiad in Informatics: 2016 Day 2, Problem 1
There are cities in Byteland, and of them are important cities frequently visited by the king of Byteland.
There are also roads in the country, each of them connecting two cities. Unfortunately, the condition of the roads is so bad that the king cannot drive through them at full speed with his sports car.
For each road, the cost for renovating it is known. Your task is to choose which roads will be renovated so that all important cities are connected with renovated roads, and the total cost is as low as possible.
Constraints
For all subtasks:
Subtask 1 [22%]
Subtask 2 [14%]
Subtask 3 [15%]
Subtask 4 [23%]
Subtask 5 [26%]
Input Specification
The first input line contains three integers , and : the number of cities, the number of important cities and the number of roads. The cities are numbered . The second input line contains integers: the important cities.
Finally, the input contains lines that describe the roads. Each line contains three integers , and , meaning that there is a bidirectional road between cities and , and the renovation cost for the road is .
You may assume that there is a route between any two cities.
Output Specification
You should output the minimum total cost for renovating the roads so that the king can travel between all important cities with his sports car.
Sample Input
4 3 6
1 3 4
1 2 4
1 3 9
1 4 6
2 3 2
2 4 5
3 4 8
Sample Output
11
Comments