#P3690. 【模板】动态树(LCT)
【模板】动态树(LCT)
Description
Given nodes and each node’s weight, you need to process the next operations.
There are four types of operations, numbered from to . Nodes are numbered from to .
0 x yasks for the sum of the weights of the nodes on the path from to . It is guaranteed that and are connected.1 x yconnects to . If and are already connected, do nothing.2 x ydeletes the edge . The existence of edge is not guaranteed.3 x ysets the weight of node to .
Input Format
The first line contains two integers and , representing the number of nodes and the number of operations.
The next lines each contain one integer. On the -th line, the integer denotes the weight of node .
The next lines each contain three integers, representing the operation type and its parameters.
Output Format
For each operation of type , output one line with one integer, the sum of the node weights on the path from to .
3 3
1
2
3
1 1 2
0 1 2
0 1 1
3
1
5 14
114
514
19
19
810
1 1 2
0 1 2
2 1 2
1 1 2
1 2 3
2 1 3
1 1 3
1 4 5
1 2 5
0 3 5
0 3 4
3 5 233333
0 1 5
0 2 5
624
315
296
232709
232823
Hint
Constraints and Conventions
For all testdata, it is guaranteed that:
- , , .
- For operations , it holds that .
- For operation , it holds that , .
Translated by ChatGPT 5
京公网安备 11011102002149号