luogu#P4784. [BalticOI 2016] 城市 (Day2)

    ID: 3807 远端评测题 3000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016枚举生成树BalticOI(波罗的海)

[BalticOI 2016] 城市 (Day2)

Problem Description

In Byteland, there are nn cities, and among them there are kk major cities that the king often visits.

There are mm roads, and each road connects two cities. Unfortunately, the poor condition of these roads prevents the king from driving at full speed.

For each road, the repair cost is given. Your task is to selectively repair roads so that all kk major cities can be connected to each other using the repaired roads, while keeping the total cost as small as possible.

Input Format

The first line contains three integers nn, kk, and mm, representing the number of cities, the number of major cities, and the number of roads. The cities are numbered 1,2,,n1,2,\dots,n.

The second line contains kk integers, representing the major cities.

The next mm lines each contain three integers aa, bb, and cc, meaning there is a bidirectional road connecting city aa and city bb, and the repair cost is cc.

Output Format

Output one line containing the minimum total cost that satisfies the above conditions.

4 3 6
1 3 4
1 2 4
1 3 9
1 4 6
2 3 2
2 4 5
3 4 8
11

Hint

For all subtasks, 1c1091 \leq c \leq 10^9 and nkn \geq k.

Subtask Score Constraints
1 22 2k5,n20,1m402 \leq k \leq 5,n \leq 20,1 \leq m \leq 40
2 14 $2 \leq k \leq 3,n \leq 10^5,1 \leq m \leq 2 \cdot 10^5$
3 15 2k4,n1000,1m20002 \leq k \leq 4,n \leq 1000,1 \leq m \leq 2000
4 23 k=4,n105,1m2105k = 4,n \leq 10^5,1 \leq m \leq 2 \cdot 10^5
5 26 k=5,n105,1m2105k = 5,n \leq 10^5,1 \leq m \leq 2 \cdot 10^5

Translated by ChatGPT 5