#P4751. 【模板】动态 DP(加强版)
【模板】动态 DP(加强版)
Description
Same as P4719.
Given a tree with nodes and node weights, perform operations that modify node weights.
After each modification, you need to output the maximum total weight of a maximum weight independent set on the tree.
Input Format
Same as P4719.
The first line contains two positive integers , , representing the number of nodes in the tree and the total number of operations.
The second line contains integers , representing the weight of each node.
The next lines each contain two integers , indicating that there is an edge connecting and .
The next lines each contain two integers , , indicating that the weight of node is modified to .
For the 1st operation, is the index of the modified node.
For the 2nd to the -th operations, the index of the modified node is .
Here, is the answer output after the previous operation, and denotes the bitwise XOR operation.
Output Format
Output lines. The -th line is the total weight of the maximum weight independent set on the tree after the -th operation.
10 10
-11 80 -99 -76 56 38 92 -51 -34 47
2 1
3 1
4 3
5 2
6 2
7 1
8 2
9 4
10 7
9 -44
184 -17
184 98
185 -58
153 48
190 99
296 -61
253 76
329 14
264 93
186
186
190
145
189
288
244
320
258
304
Hint
Constraints: , . It is guaranteed that at any time, the absolute value of each node weight is .
The time limit is twice that of the reference solution. If you need to optimize constants, please use the int type.
Translated by ChatGPT 5
京公网安备 11011102002149号