DRANG001 - Santa s Reindeers
An disease has attacked the reindeers and made them unable to fly to deliver Christmas gifts.
The reindeer elves have managed to identify a rather curious fact about this disease, which is contagious only if two or more diseased reindeer are in the same stable.
Each reindeer is in a room that is connected to another room by a corridor with W meters, where these connected rooms form a stable. The solution, proposed by the elves experts, was that old Santa removed some corridors for the disease to be controlled. To remove a corridor of W meters is necessary Whours and as it is very close to Christmas, Santa asked for his help to minimize the time.
Help Santa determine the minimum time as possible so the disease does not
Santa's Tip: Initially there is only one stable, meaning all rooms are connected and there is no circular path.
Input
The first line contains two integers N (1≤N≤2×105) the number of reindeers and M (0≤M≤N) the number of reindeer that were diagnosed with the disease. Then follow M integers, where the whole Mi is the index of the sick reindeer's room. Then follow N−1 lines each with three integers U, V, W, where (U≠V) e (0≤U,V<N) and (1≤W≤1×106) there is a W-sized corridor that connects rooms U and V (the corridor can be used in either direction).
Output
The minimum time for the disease to not spread.
Example
Input:6 3
0 5 3
0 1 5
0 4 3
0 3 3
2 3 1
5 4 9
Output: 6
Example
Input:7 4
0 1 2 3
0 1 3
1 2 5
2 3 6
6 0 1
4 5 3
6 5 4
Output: 14
Added by: | Francisco Elio Parente Arcos Filho [UEA] |
Date: | 2018-12-25 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | https://www.urionlinejudge.com.br/judge/en/challenges/view/412/7 |