#P3206. [HNOI2010] 城市建设
[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 , representing the number of cities, the number of roads that can be built, and the number of notifications, respectively.
The next lines: on the -th line there are three integers , meaning the cost to build a road between city and city is . Then the next lines: each line contains two integers , meaning the construction cost of the -th road is updated to (that is, set to ).
Output Format
Output contains lines. On the -th line, output the minimal total cost to make all cities connected after processing the first 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 of the testdata, , .
- For another of the testdata, , , . The updated cost will not be lower than the previous cost.
- For of the testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号