QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100

#16280. 城市建设

統計

PS country is a large country with many cities. King Louis has been racking his brains over the construction of roads between cities. Louis can build roads between certain cities, and building roads between different cities requires different costs. Louis wants to build the minimum number of roads to make all cities in the country connected. However, due to certain factors, the cost of building roads between cities changes from time to time. Louis will continuously receive messages about changes in road construction costs. He wants to know the minimum total cost to make the cities connected immediately after receiving each message. Louis has decided to ask you for help with this task.

Input

The first line of input contains three space-separated integers $N, M, Q$, representing the number of cities, the number of roads that can be built, and the number of messages received, respectively. The next $M$ lines follow. The $(i+1)$-th line contains three space-separated integers $X_i, Y_i, Z_i$ ($1 \le X_i, Y_i \le N, 0 \le Z_i \le 50000000$), indicating that the cost of building a road between city $X_i$ and city $Y_i$ is $Z_i$. The following $Q$ lines each contain two space-separated integers $K_j$ and $D_j$, indicating that the construction cost of the $K_j$-th road entered previously is modified to $D_j$.

The input data guarantees:

  • 20% of the data satisfies $N \le 1000, M \le 6000, Q \le 6000$.
  • 20% of the data satisfies $N \le 1000, M \le 50000, Q \le 8000$, and the modified cost will not be lower than the previous cost.
  • 100% of the data satisfies $N \le 20000, M \le 50000, Q \le 50000$.

Output

The output contains $Q$ lines. The $i$-th line outputs the minimum total cost to make the cities connected after receiving the first $i$ messages.

Examples

input.txt

5 5 3
1 2 1
2 3 2
3 4 3
4 5 4
5 1 5
1 6
1 1
5 3

output.txt

14
10
9

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.