Given vertices and weighted bidirectional edges, Bruce knows how to find the Minimal Spanning Tree (MST). But if the weight of each edge is changing, Bruce doesn't know how to efficiently find the MST after each change. Can you write a program to help Bruce?
Input Specification
The first line of input will consist of three integers, , and , which are the number of vertices, number of edges, and number of weight changes.
Each of the next lines will consist of three integers, , and (, ), which represents the bidirectional edge between and has the cost .
Each of the next lines will consist of two integers, and (, ), which represents the th edge's cost changes to .
Output Specification
Output lines. The line consists of 1 integer, the cost of MST after the first changes.
Constraints
20% cases , , .
40% cases , , .
100% cases , , .
Sample Input
5 5 3
1 2 1
2 3 2
3 4 3
4 5 4
5 1 5
1 6
1 1
5 3
Sample Output
14
10
9
Comments
What if graph doesn't have minimum spanning tree?
For anyone solving this problem in the future, it is guaranteed that the graph is connected.
block size 400 is more effective than either block size 500, 200, 250, 125 or 100
It does seem to vary based on the implementation
Time complexity is supposed to be and time limit is supposed to be 2 sec.