#P6798. 「StOI-2」简单的树
「StOI-2」简单的树
Description
Given a rooted tree with root and nodes. Each node has a weight .
Define the value of each node as: the maximum among all nodes in the subtree rooted at this node.
Define the function as the sum of over the entire tree after changing to .
Now you need to answer queries. Each query gives three values , and you need to compute modulo .
Input Format
This problem is forced online.
The first line contains three positive integers , , and , representing the number of nodes in the tree, the number of queries, and a value controlling the forced-online behavior.
The second line contains positive integers, representing the weight of each node.
The next lines each contain two positive integers and , representing an edge of the tree.
The next lines each contain three positive integers . You need to compute the real and then answer the query.
Here, is the answer to the previous query, initially .
If , swap and .
Output Format
For each query, output the final answer.
5 3 0
5 3 4 2 1
1 2
1 3
2 4
2 5
1 3 5
2 4 1
1 3 4
42
48
52
Hint
Sample Explanation
The real are:
Constraints
For of the testdata: 。
For of the testdata: 。
For another of the testdata: 。
For another of the testdata: 。
For the first of the testdata: 。
For of the testdata: , 。
Translated by ChatGPT 5
京公网安备 11011102002149号