#P11161. 【MX-X6-T7】夏が終わる
【MX-X6-T7】夏が終わる
Background
Original link: https://oier.team/problems/X6H.
Knowing the end of summer We are reflected in the drops of ramune As if we might lose sight of it Chasing those sunset-red cheeks We will come back here again next year
A year passes, you walk a full loop, and return to the starting point.
In this world of nonstop change, will there still be a chance to meet you again? When choosing an optimal path, how big is that chance?
Problem Description
Given a tree with nodes, with weighted edges. Define an undirected complete graph :
- It contains nodes.
- If contains an edge , then the weight of edge in is the weight of that edge; otherwise it is .
Let be the weight of the minimum-weight Hamiltonian cycle in .
You are given modification operations, of two types:
- Delete one edge in and then add one edge, guaranteeing that after each operation it is still a tree.
- Given a path in , increase the weight of every edge on that path by a value.
You need to compute after each operation.
Input Format
The first line contains two positive integers .
The next lines each contain three positive integers , describing an edge in the tree. The edges are numbered in the input order.
The next lines each contain or integers. The first integer is the operation type :
- If , it means a delete-edge-then-add-edge operation. The next integers are in order: is the index of the edge deleted in this operation; describe the new edge added. These newly added edges are numbered consecutively in the operation order starting from .
- If , it means a path-add operation. The next integers are : increase the weight of every edge on the simple path between and in the tree by .
Output Format
Print lines, each containing one integer: the value of after the corresponding operation.
5 3
1 2 1
2 3 1
3 4 1
4 5 1
1 4 3 5 1
2 1 5 1
1 1 1 3 100
1
1
3
6 12
3 5 18
3 1 8
5 6 3
6 4 10
6 2 8
1 4 3 4 10
1 5 6 2 5
2 2 5 1
1 7 3 2 19
2 4 6 1
1 3 5 6 20
2 3 4 1
1 9 5 6 16
2 3 1 32
2 3 4 30
2 3 5 22
2 3 2 21
0
0
0
8
8
8
8
8
12
19
19
40
Hint
Sample Explanation #1
After the first operation, the shape of is as follows:

The tree edges are marked in red. One of the optimal Hamiltonian cycles is .
Constraints
For all testdata, it is guaranteed that , , , . It is guaranteed that at any time the edge weight does not exceed . It is guaranteed that an edge that has already been deleted will not be deleted again.
Bundled tests, with 5 subtasks. The detailed limits are as follows:
- Subtask 1 (6 pts): , .
- Subtask 2 (27 pts): .
- Subtask 3 (15 pts): all answers are .
- Subtask 4 (26 pts): , .
- Subtask 5 (26 pts): no special limits.
Translated by ChatGPT 5