#P3264. [JLOI2015] 管道连接
[JLOI2015] 管道连接
Description
Xiao Mingming recently joined an intelligence department, which is struggling with how to establish secure pipeline connections. The department has intelligence stations, numbered from to . You are given pairs of stations with a cost , meaning that a pipeline can be built between station and station at a resource cost of .
If one station can reach another station through several built pipelines, then these two stations are considered connected. Formally, if a pipeline is built between and , then they are connected; if and are both connected to , then and are also connected.
Among all stations, there are important stations, and each of these stations has a specific channel. The task is to spend the minimum total amount of resources so that any two stations with the same channel are connected.
Input Format
The first line contains three integers , representing the number of stations, the number of possible pipelines, and the number of important stations.
Each of the next lines contains three integers , describing a possible pipeline.
Finally, there are lines, each containing two integers , representing the channel and the station index of an important station.
Output Format
Output a single integer on one line, the minimum total amount of resources required so that any two stations with the same channel are connected.
5 8 4
1 2 3
1 3 2
1 5 1
2 4 2
2 5 1
3 4 3
3 5 1
4 5 1
1 1
1 2
2 3
2 4
4
Hint
Choose , , , to connect these pairs of stations.
For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号