#P3264. [JLOI2015] 管道连接

    ID: 2313 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2015吉林状态压缩,状压生成树

[JLOI2015] 管道连接

Description

Xiao Mingming recently joined an intelligence department, which is struggling with how to establish secure pipeline connections. The department has nn intelligence stations, numbered from 11 to nn. You are given mm pairs of stations (ui,vi)(u_i,v_i) with a cost wiw_i, meaning that a pipeline can be built between station uiu_i and station viv_i at a resource cost of wiw_i.

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 uiu_i and viv_i, then they are connected; if uiu_i and viv_i are both connected to tit_i, then uiu_i and viv_i are also connected.

Among all stations, there are pp 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 n,m,pn,m,p, representing the number of stations, the number of possible pipelines, and the number of important stations.

Each of the next mm lines contains three integers ui,vi,wiu_i,v_i,w_i, describing a possible pipeline.

Finally, there are pp lines, each containing two integers ci,dic_i,d_i, 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 (1,5)(1,5), (3,5)(3,5), (2,5)(2,5), (4,5)(4,5) to connect these 44 pairs of stations.

For 100%100\% of the testdata, 1cip101\le c_i\le p\le10, 1ui,vi,din10001\le u_i,v_i,d_i \le n \le 1000, 0m30000\le m \le 3000, 0wi2×1040\le w_i \le 2\times 10^4.

Translated by ChatGPT 5