#4628. [UTS 2024] Remove Node
[UTS 2024] Remove Node
[UTS 2024] Remove Node
题目描述
You have a rooted tree with $n$ vertices, each assigned a value $a_x$. The root is node $1$.You can perform operations where you merge two adjacent nodes and into a single node , with the value of being equal to the minimum value between the two nodes. This operation changes edges connected to or to be connected to . The cost of this operation is . The total cost of multiple operations is the sum of individual operation costs.
For queries, you have two types:
- : This updates the value of node to .
- : This asks for the minimum cost of operations to reduce the subtree rooted at to just one node.
输入格式
The first line contains a single integer $n$ $(1 \le n \le 200\,000)$, the number of vertices.The second line contains integers , representing the assigned values of each node.
The third line contains integers (), representing the parent of each node.
The fourth line contains one integer , representing the total number of queries.
The following lines each contain a query:
Either (, ), or ().
输出格式
On each line of the input, you need to print the result of a query of type $2$, in the same order as the order from the input.7
4 7 9 7 4 1 2
1 1 3 2 3 2
1
2 1
11
7
6 6 5 1 6 6 4
1 1 2 3 3 3
3
2 1
1 1 1
2 1
7
11