#P1501. [国家集训队] Tree II
[国家集训队] Tree II
Description
A tree with nodes, where each node’s initial weight is .
There are operations on this tree, each being one of the following four types:
+ u v c: Add a natural number to the weight of every node on the path from to .- u1 v1 u2 v2: Delete the existing edge from the tree and add a new edge . It is guaranteed that after the operation it is still a tree.* u v c: Multiply the weight of every node on the path from to by a natural number ./ u v: Query the sum of the weights of all nodes on the path from to , and output the answer modulo .
Input Format
The first line contains two integers .
Each of the next lines contains two positive integers , describing one edge of the tree.
Each of the next lines describes one operation.
Output Format
For each query operation, output one integer per line as the answer.
3 2
1 2
2 3
* 1 3 4
/ 1 1
4
Hint
Constraints
- For of the testdata, .
- For an additional of the testdata, , there are no
-operations, and the initial tree is a chain. - For an additional of the testdata, , there are no
-operations. - For of the testdata, , .
By (Wu Yiming).
Translated by ChatGPT 5
京公网安备 11011102002149号