#P6845. [CEOI 2019] Dynamic Diameter
[CEOI 2019] Dynamic Diameter
Description
There is a tree with nodes, and the edges are weighted.
There will be modifications. Each modification changes the weight of one edge in the tree. After each modification, you need to output the sum of edge weights on the diameter of the tree.
This problem is strictly online.
Input Format
The first line contains three integers , representing the number of nodes, the number of queries, and the upper bound of edge weights.
The next lines each contain three integers , meaning there is an edge between and with weight .
The next lines each contain two encrypted integers .
The decryption method is:
Here, is the answer to the previous query, with initial value .
This means: change the weight of the -th edge to .
Output Format
Output lines. Each line contains one integer. The integer on the -th line is the total weight on the diameter after the -th modification.
4 3 2000
1 2 100
2 3 1000
2 4 1000
2 1030
1 1020
1 890
2030
2080
2050
10 10 10000
1 9 1241
5 6 1630
10 5 1630
2 6 853
10 1 511
5 3 760
8 3 1076
4 10 1483
7 10 40
8 2051
5 6294
5 4168
7 1861
0 5244
6 5156
3 3001
8 5267
5 3102
8 3623
6164
7812
8385
6737
6738
7205
6641
7062
6581
5155
Hint
Explanation of Sample 1
The decrypted modifications are:
2 1030
0 1050
2 970
The following figure shows how the edge weights in the tree change. The red edge represents the diameter of the tree:

Constraints
For of the testdata, it is guaranteed that , , , , , and .
The detailed subtask constraints and scores are shown in the table below:
| Subtask ID | Constraints | Score |
|---|---|---|
| 1 | and | |
| 2 | and | |
| 3 | and all edges are of the form | |
| 4 | and all edges are of the form or | |
| 5 | It is guaranteed that there exists a diameter that passes through node | |
| 6 | No special constraints |
Notes
This problem is translated from Central-European Olympiad in Informatics 2019 Day 1 T2 Dynamic Diameter。
Translated by ChatGPT 5
京公网安备 11011102002149号