luogu#P1505. [国家集训队] 旅游
[国家集训队] 旅游
Background
Ray loves traveling, and this time he has arrived in T City. T City is a city of waterways with attractions, and some pairs of attractions are connected by a bridge. To make it easy for tourists to reach every attraction while saving costs, there is exactly one path between any two attractions. In other words, there are only bridges in T City.
Ray noticed that some bridges offer beautiful scenery that lifts the mood, while others are narrow and muddy, which is frustrating. So he assigns a pleasure value to each bridge, meaning Ray’s pleasure increases by when he crosses that bridge, which could be positive or negative. Sometimes, Ray’s feelings about the same bridge also change.
Now, Ray wants you to help him compute the total pleasure he can get when traveling from attraction to attraction . Sometimes he also wants to know the maximum pleasure provided by the most beautiful bridge on a certain route, or the minimum pleasure provided by the worst bridge on a certain route.
Problem 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