#P3206. [HNOI2010] 城市建设

    ID: 2255 远端评测题 3000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2010湖南分治生成树Link-Cut Tree,LCT

[HNOI2010] 城市建设

Description

The PS Kingdom is a large country with many cities. King Louis has racked his brains over urban transportation. Louis can build roads between certain pairs of cities, and building roads between different pairs costs different amounts.

Louis wants to build the fewest roads so that all cities in the country are connected. However, due to certain factors, the cost to build roads between cities changes over time. Louis will continuously receive notifications that the construction cost of some road has changed. He hopes that after receiving each notification, he can immediately know the minimal total cost to connect all cities. Louis has decided to ask you for help with this task.

Input Format

The first line contains three integers n,m,qn, m, q, representing the number of cities, the number of roads that can be built, and the number of notifications, respectively.

The next mm lines: on the (i+1)(i + 1)-th line there are three integers xi,yi,zix_i, y_i, z_i, meaning the cost to build a road between city xix_i and city yiy_i is ziz_i. Then the next qq lines: each line contains two integers k,dk, d, meaning the construction cost of the kk-th road is updated to dd (that is, set zkz_k to dd).

Output Format

Output contains qq lines. On the ii-th line, output the minimal total cost to make all cities connected after processing the first ii notifications.

5 5 3
1 2 1
2 3 2
3 4 3
4 5 4
5 1 5
1 6
1 1
5 3
14
10
9

Hint

Constraints

  • For 20%20\% of the testdata, n103n \le 10^3, m,q6×103m, q \le 6 \times 10^3.
  • For another 20%20\% of the testdata, n103n \le 10^3, m5×104m \le 5 \times 10^4, q8×103q \le 8 \times 10^3. The updated cost will not be lower than the previous cost.
  • For 100%100\% of the testdata, 1n2×1041 \le n \le 2 \times 10^4, 1m,q5×1041 \le m, q \le 5 \times 10^4, 1xi,yin1 \le x_i, y_i \le n, 0zi5×1070 \le z_i \le 5 \times 10^7.

Translated by ChatGPT 5