#P1505. [国家集训队] 旅游
[国家集训队] 旅游
Description
You are given a tree with nodes, edges have weights, and nodes are numbered . You need to support five operations. Edges are indexed by their input order from to .
C i wChange the weight of the -th edge in the input to .N u vNegate the weights of all edges on the path between and .SUM u vQuery the sum of edge weights on the path between and .MAX u vQuery the maximum edge weight on the path between and .MIN u vQuery the minimum edge weight on the path between and .
At any time, all edge weights are within .
Input Format
The first line contains a positive integer , the number of nodes. The next lines each contain three integers , indicating that there is an edge between and with weight , describing the tree. Then a line with a positive integer , the number of operations. The next lines each describe one operation.
Output Format
For each query operation, output one line with one integer representing the answer.
3
0 1 1
1 2 2
8
SUM 0 2
MAX 0 2
N 0 1
SUM 0 2
MIN 0 2
C 1 3
SUM 0 2
MAX 0 2
3
2
1
-1
5
3
Hint
Constraints
For of the testdata, .
2020.02.04 Fixed a small error in the testdata. 2020.03.14 Added a set of hack testdata. 2020.11.26 Added a set of hack testdata by @_Leaving.
Translated by ChatGPT 5
京公网安备 11011102002149号