Limits 1s, 512 MB

Hermione Granger is in trouble. Using Floo powder, she somehow ended in a pub in Knockturn Alley. The alley contains numerous shops devoted to the Dark Arts. Few shops contain Flesh-Eating Slugs too. These slugs can't do much harm alone, but when two of them join together, they become a force to be reckoned with. They can even destroy the world! Currently no shop has multiple slugs in them.

Luckily, Hermione has a map similar to the Marauder's Map showing the shops that contain these slugs. She wants to destroy the roads connecting the shops containing the slugs in order to stop them from joining forces.

Knockturn Alley can be considered as shops connected by bidirectional roads. There's a unique path between any pair of shops. Each of the roads connecting the shops take an amount of time to be destroyed, and Hermione alone can destroy only one road at a time. Can you help her find the minimum time to stop the attack?

Input

The first line of the input contains two space-separated integers, n (2 <= n < 10^5) and k (2 <= k <= n), the number of shops and the number of shops containing slugs currently. Each of the following n-1 lines contains three space-separated integers, shop1, shop2 and time (1<= time <= 10^6) meaning there's a bidirectional road connecting shop1 and shop2, and to destroy this road, it takes time units. Next k lines contain a single integer, slug[i], the label of the shop with a slug.

Output

Print a single integer denoting the minimum time required to disrupt the connection among all the slugs.

Sample

InputOutput
5 3
2 1 8
1 0 5
2 4 5
1 3 4
2
4
0
10

Submit

Login to submit.

Statistics

60% Solution Ratio
prodip_bsmrstuEarliest, Oct '19
nusuBotFastest, 0.0s
prodip_bsmrstuLightest, 7.2 MB
prodip_bsmrstuShortest, 3650B
Toph uses cookies. By continuing you agree to our Cookie Policy.