#P2700. 逐个击破
逐个击破
Description
There are cities, among which are occupied by enemy corps. There are roads connecting the cities. The cost to destroy any given road is known. You are given the cities occupied by the enemy and the destruction cost of every road. Please compute the minimum total cost to isolate these 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 and .
- The second line contains integers, indicating which cities are occupied by the enemy.
- The next lines each contain three positive integers , indicating there is a road between city and city , and the cost to destroy it is . City indices start from .
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 of the testdata, .
- For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号