visiting

Problem Description

Gug is going visiting! In the town that Gug lives in, there are a total of N houses and N - 1 roads, and each road i connects houses Ai and Bi, taking Ci minutes to travel in either direction. It is guaranteed that it is possible to travel from each house to another directly or indirectly using these roads.

Gug needs to visit a total of K of these houses. The ith house that Gug needs to visit is house Vi, and Gug needs to visit all the houses in some order during the day. At the start of the day, Gug can choose any house to start at, and then must travel from house to house such that he reaches all the houses that he needs to visit at least once. Assuming it takes a negligible amount of time for Gug to do the actual visiting, and Gug can end the day at any house, what is the minimum amount of time required for Gug to complete his visits?

Input

The first line of input will contain two integers, N and K.

The second line of input will contain K integers, representing the array V. V will not contain any number twice.

The next N - 1 lines of input will contain three integers each, Ai, Bi and Ci.

Output

The output should contain one integer, the minimum amount of time, in minutes, Gug needs to complete his visiting.

Limits

For all subtasks: 1 ≤ Ci ≤ 109, 0 ≤ Ai, Bi, Vi < N.

Subtask 1 (17%): 2 ≤ K ≤ N ≤ 8.

Subtask 2 (20%): 2 ≤ K ≤ N ≤ 1000.

Subtask 3 (15%): 2 ≤ N ≤ 200000, K = 2.

Subtask 4 (22%): 2 ≤ K = N ≤ 200000.

Subtask 5 (26%): 2 ≤ K ≤ N ≤ 200000.

Subtask 6 (0%): Sample Testcases.

Sample Input 1

7 3
4 0 6
0 2 4
2 4 3
4 5 2
2 1 1
1 3 5
1 6 2

Sample Output 1

13

Explanation

Gug visits 0, 4 then 6.



Submitting .cpp to 'visiting'


You're not logged in! Click here to login

Time Limit: 1 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: Dunjudge Archive

Subtask Score
1 17
2 20
3 15
4 22
5 26
6 0