시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
4 초 256 MB 1 1 1 100.000%

문제

There are n cities in Byteland, and k of them are important cities frequently visited by the king of Byteland.

There are also m 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 k important cities are connected with renovated roads, and the total cost is as low as possible.

입력

The first input line contains three integers n, k and m: the number of cities, the number of important cities and the number of roads. The cities are numbered 1, 2, ..., n. The second input line contains k integers: the important cities.

Finally, the input contains m lines that describe the roads. Each line contains three integers a, b and c, meaning that there is a bidirectional road between cities a and b, and the renovation cost for the road is c.

You may assume that there is a route between any two cities.

  • 1 ≤ c ≤ 109
  • n ≥ k
  • 2 ≤ k ≤ 5
  • n ≤ 105
  • 1 ≤ m ≤ 2 ⋅ 105

출력

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.

예제 입력

4 3 6
1 3 4
1 2 4
1 3 9
1 4 6
2 3 2
2 4 5
3 4 8

예제 출력

11

힌트