#P4719. 【模板】动态 DP
【模板】动态 DP
Description
Given a tree with nodes, each node has a weight.
There are operations. In each operation, you are given , which means changing the weight of node to .
After each operation, you need to output the total weight of the maximum weight independent set of this tree.
Input Format
The first line contains two integers, representing the number of nodes and the number of operations .
The second line contains integers. The -th integer is the weight of node .
In the next lines, each line contains two integers , indicating that there is an edge connecting and .
In the next lines, each line contains two integers , indicating an operation that changes the weight of node to .
Output Format
For each operation, output one line with one integer representing the answer.
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
2 -17
2 98
7 -58
8 48
3 99
8 -61
9 76
9 14
10 93
186
186
190
145
189
288
244
320
258
304
Hint
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号