## Dynamic MST

View as PDF

Points: 40 (partial)
Time limit: 4.0s
Memory limit: 128M

Author:
Problem type

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.

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

• koosaga  commented on Jan. 1, 2018, 9:46 a.m.

What if graph doesn't have minimum spanning tree?

• Kirito  commented on Feb. 26, 2019, 10:36 a.m.

For anyone solving this problem in the future, it is guaranteed that the graph is connected.

• imaxblue  commented on March 14, 2017, 11:09 p.m.

block size 400 is more effective than either block size 500, 200, 250, 125 or 100

• wleung_bvg  commented on Aug. 24, 2017, 4:09 a.m.

It does seem to vary based on the implementation

• bruce  commented on Aug. 24, 2017, 8:40 a.m.

Time complexity is supposed to be O(QlogNlogN) and time limit is supposed to be 2 sec.