#P12536. [XJTUPC 2025] 我永远喜欢希儿·芙乐艾

[XJTUPC 2025] 我永远喜欢希儿·芙乐艾

Description

Please note the unusual space constraints for this problem.

Given an operation sequence\textbf{an operation sequence} AA and a rooted tree TT, each operation in AA is like ''add xx to all point weights on the simple path from uu to vv in TT.'' The simple path from uu to vv is defined as a path starting from uu and ending at vv that does not repeatedly visit any nodes or edges.

Initially, the root of TT is 11, and all point weights are 00.

You need to perform three operations:

  • Given an interval [l,r][l,r], perform operations from Al,Al+1A_l, A_{l+1}\dots to ArA_r in sequence;
  • Query the sum of the subtrees of TT with xx as the root;
  • Change the root of TT to yy (If the current root is yy, no operation will be performed).

Input Format

The first line contains three positive integers n1n_1, n2n_2, and mm (1n1,n2,m1×1051\le n_1,n_2,m \le 1\times 10^5), separated by a space, representing the length of AA, the total number of points in TT, and the number of inquiries and operations.

The next n1n_1 lines, the ii-th line contains three integers uiu_i, viv_i, and xix_i (1ui,vin2,1xi1×1021\le u_i,v_i\le n_2, 1\le x_i\le 1\times 10^2), separated by a space, representing the operation AiA_i as ''add xix_i to all point weights on the simple path from uiu_i to viv_i in TT.''

Next, there are n21n_2-1 lines, each containing two positive integers uu and vv (1u,vn21\le u,v \le n_2), separated by a space, representing an edge of the tree. It is guaranteed that the n21n_2-1 edges form a tree.

Next, there are mm lines. The first number opop (op{1,2,3}op\in \{1,2,3\}) in each line indicates the operation number, followed by:

  • If opop is 11, it is followed by two positive integers ll and rr (1lrn11\le l\le r\le n_1), separated by a space, indicating that the operations of Al,Al+1ArA_l, A_{l+1} \dots A_r are executed in sequence;
  • If opop is 22, it is followed by a positive integer xx (1xn21\le x\le n_2), indicating that the sum of the subtrees of TT with xx as the root is queried;
  • If opop is 33, it is followed by a positive integer yy (1yn21\le y\le n_2), indicating that the root of TT is changed to yy (If the current root is yy, no operation will be performed).

Output Format

For each operation 22, output one line of one integer, representing the sum of the subtrees of TT with xx 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