#abc355f. F - MST Query
F - MST Query
Score : points
问题陈述
给定一个权重无向连通图 ,包含 个顶点和 条边,顶点编号从 到 ,边编号从 到 。边 连接顶点 和 ,权重为 。
你需要依次处理 个查询。第 个查询描述如下:
- 给定整数 。在 中添加一条连接顶点 和 的边,权重为 。然后,打印 的最小生成树中边的权重之和。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a weighted undirected connected graph with vertices and edges, where vertices are numbered to and edges are numbered to . Edge connects vertices and with a weight of .
You are given queries to process sequentially. The -th query is described as follows:
- You are given integers . Add an edge with weight between vertices and in . Then, print the sum of the weights of the edges in a minimum spanning tree of .
Constraints
- The graph is connected before processing the queries.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -th query.
Sample Input 1
4 4
1 2 6
2 3 5
2 4 4
1 3 3
1 2 3
1 4 10
3 4 1
Sample Output 1
12
10
10
7
Here is the graph after adding the edge for each query. The edges included in the minimum spanning tree are colored red.
Sample Input 2
8 6
1 8 8
1 6 10
1 5 8
2 6 6
6 7 6
1 3 9
2 4 7
1 3 4
1 6 7
3 4 6
1 5 1
7 8 4
3 5 3
Sample Output 2
49
46
45
38
34
33