Orange Boy Can You Solve It Out? Ep.18.5 (the lost obcysio)

Solved!
Difficulty: Div2D-Div2E

Note: this problem is drafted on 2019/7/30 by XGN and not released. It's now released on 2022/1/2 by Zzzyt under his permission.

Statement

Yuqi has an rooted indexed tree TT of NN nodes indexed from 1 to NN. The node 1 is the root. Now on each node there is an enemy with Health Point(HP) viv_i and Yuqi has to defeat them.
He can cast several kinds of magic:

  • Magic Kind 1: given aa bb increase the HP in the subtree of node aa by bb. (1aN,0b1091\leq a\leq N,0\leq |b|\leq 10^9)

  • Magic Kind 2: given aa bb increase the HP of node aa by bb. (1aN,0b1091\leq a\leq N,0\leq |b|\leq 10^9)

  • Magic Kind 3: given aa if aa is in the Blacklist remove it, otherwise add it into the blacklist. (1aN1\leq a\leq N)

  • Magic Kind 4: given aa.tell Yuqi the HP of node aa. (1aN1\leq a\leq N)

Nodes in Blacklist's HP will not be affected by any other magic until it's removed.
Now he gives you the list of magic to proceed. You need to proceed them in order. Note that the enemy's HP can be negative at any moment without dying.

Input

The first line contains one integer NN. (1N1051\leq N\leq 10^5)
The next n1n-1 lines each contains two numbers xx yy (1x,yN1\leq x,y\leq N) indicating an edge.
The next line contains NN integers, the array VV. (1Vi1091\leq V_i\leq 10^9)
The following line contains one integer qq - the number of magic to proceed.(1q1051\leq q\leq 10^5)
Then next qq lines can be:

  • 1 a b Magic Kind 1
  • 2 a b Magic Kind 2

  • 3 a Magic Kind 3

  • 4 a Magic Kind 4

Output

For each magic 4, print the answer in a line.

Example

Input

4
1 2
1 3
2 4
1 2 3 4
7
3 3
1 1 1
2 2 2
4 1
4 2
4 3
4 4

Output

2
4
3
5

Solution

By XGN:

This problem has been included in Hackerearth Data Structures and Algorithms coding challenge

版权声明:
作者:admin
链接:https://blog.hellholestudios.top/archives/237
来源:Hell Hole Studios Blog
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>
目 录