#P12536. [XJTUPC 2025] 我永远喜欢希儿·芙乐艾
[XJTUPC 2025] 我永远喜欢希儿·芙乐艾
Description
Please note the unusual space constraints for this problem.
Given and a rooted tree , each operation in is like ''add to all point weights on the simple path from to in .'' The simple path from to is defined as a path starting from and ending at that does not repeatedly visit any nodes or edges.
Initially, the root of is , and all point weights are .
You need to perform three operations:
- Given an interval , perform operations from to in sequence;
- Query the sum of the subtrees of with as the root;
- Change the root of to (If the current root is , no operation will be performed).
Input Format
The first line contains three positive integers , , and (), separated by a space, representing the length of , the total number of points in , and the number of inquiries and operations.
The next lines, the -th line contains three integers , , and (), separated by a space, representing the operation as ''add to all point weights on the simple path from to in .''
Next, there are lines, each containing two positive integers and (), separated by a space, representing an edge of the tree. It is guaranteed that the edges form a tree.
Next, there are lines. The first number () in each line indicates the operation number, followed by:
- If is , it is followed by two positive integers and (), separated by a space, indicating that the operations of are executed in sequence;
- If is , it is followed by a positive integer (), indicating that the sum of the subtrees of with as the root is queried;
- If is , it is followed by a positive integer (), indicating that the root of is changed to (If the current root is , no operation will be performed).
Output Format
For each operation , output one line of one integer, representing the sum of the subtrees of with as the root.
The data ensures that the answer is within the range expressed by a signed long long integer.
4 5 7
3 5 2
5 4 3
3 1 2
2 5 1
2 1
4 2
1 5
3 2
1 1 4
2 1
1 2 3
2 2
3 3
1 1 3
2 2
29
25
63
京公网安备 11011102002149号