#P2700. 逐个击破

逐个击破

Description

There are NN cities, among which KK are occupied by enemy corps. There are N1N - 1 roads connecting the NN cities. The cost to destroy any given road is known. You are given the KK cities occupied by the enemy and the destruction cost of every road. Please compute the minimum total cost to isolate these KK enemy corps from each other, so that in the second step they can be eliminated one by one.

Input Format

  • The first line contains two positive integers NN and KK.
  • The second line contains KK integers, indicating which cities are occupied by the enemy.
  • The next N1N - 1 lines each contain three positive integers a,b,ca, b, c, indicating there is a road between city aa and city bb, and the cost to destroy it is cc. City indices start from 00.

Output Format

Output a single line with one integer, the minimum total cost.

5 3
1 2 4
1 0 4
1 3 8
2 1 1
2 4 3
4

Hint

Constraints:

  • For 10%10\% of the testdata, N10N \le 10.
  • For 100%100\% of the testdata, 2N1052 \le N \le 10^5, 2KN2 \le K \le N, 1c1061 \le c \le 10^6.

Translated by ChatGPT 5