beecrowd | 2932

# Santa's Reindeers

By Diego Rangel, FACIT Brazil

Timelimit: 1

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 $$W$$ hours 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 \leq N \leq 2 \times 10^{5})$$ the number of reindeers and M $$(0 \leq M \leq N)$$ the number of reindeer that were diagnosed with the disease. Then follow $$M$$ integers, where the whole $$M_{i}$$ is the index of the sick reindeer's room. Then follow $$N-1$$ lines each with three integers U, V, W, where $$(U \neq V)$$ e $$(0 \leq U, V < N)$$ and $$(1 \leq W \leq 1 \times 10^{6})$$ 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.

 Input Samples Output Samples 6 3 0 5 3 0 1 5 0 4 3 0 3 3 2 3 1 5 4 9 6
 7 4 0 1 2 3 0 1 3 1 2 5 2 3 6 6 0 1 4 5 3 6 5 4 14