Codeforces Round 457 (Div. 2)
E
Jamie and Tree
Codeforces
2400
原题
← D→
翻译中…

To your surprise, Jamie is the final boss! Ehehehe.

翻译中…

Jamie has given you a tree with $*n*$ vertices, numbered from $1$ to $*n*$. Initially, the root of the tree is the vertex with number $1$. Also, each vertex has a value on it.

翻译中…

Jamie also gives you three types of queries on the tree:

翻译中…

$1 *v*$ — Change the tree's root to vertex with number $*v*$.

翻译中…

$2 *u* *v* *x*$ — For each vertex in the subtree of smallest size that contains $*u*$ and $*v*$, add $*x*$ to its value.

翻译中…

$3 *v*$ — Find sum of values of vertices in the subtree of vertex with number $*v*$.

翻译中…

A subtree of vertex $*v*$ is a set of vertices such that $*v*$ lies on shortest path from this vertex to root of the tree. Pay attention that subtree of a vertex can change after changing the tree's root.

翻译中…

Show your strength in programming to Jamie by performing the queries accurately!

翻译中…

Input

翻译中…

The first line of input contains two space-separated integers $*n*$ and $*q*$ ($1 ≤ *n* ≤ 10^{5}, 1 ≤ *q* ≤ 10^{5}$) — the number of vertices in the tree and the number of queries to process respectively.

翻译中…

The second line contains $*n*$ space-separated integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($- 10^{8} ≤ *a*_{*i*} ≤ 10^{8}$) — initial values of the vertices.

翻译中…

Next $*n* - 1$ lines contains two space-separated integers $*u*_{*i*}, *v*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$) describing edge between vertices $*u*_{*i*}$ and $*v*_{*i*}$ in the tree.

翻译中…

The following $*q*$ lines describe the queries.

翻译中…

Each query has one of following formats depending on its type:

翻译中…

$1 *v*$ ($1 ≤ *v* ≤ *n*$) for queries of the first type.

翻译中…

$2 *u* *v* *x*$ ($1 ≤ *u*, *v* ≤ *n*,  - 10^{8} ≤ *x* ≤ 10^{8}$) for queries of the second type.

翻译中…

$3 *v*$ ($1 ≤ *v* ≤ *n*$) for queries of the third type.

翻译中…

All numbers in queries' descriptions are integers.

翻译中…

The queries must be carried out in the given order. It is guaranteed that the tree is valid.

翻译中…

Output

翻译中…

For each query of the third type, output the required answer. It is guaranteed that at least one query of the third type is given by Jamie.

翻译中…

Note

翻译中…

The following picture shows how the tree varies after the queries in the first sample.

翻译中…

image

翻译中…

样例

Input #1
6 7
1 4 2 8 5 7
1 2
3 1
4 3
4 5
3 6
3 1
2 4 6 3
3 4
1 6
2 2 4 -5
1 4
3 3
Output #1
27
19
5
InputCopy OutputCopy
Input #2
4 6
4 3 5 6
1 2
2 3
3 4
3 1
1 3
2 2 4 3
1 1
2 2 4 -3
3 1
Output #2
18
21
InputCopy OutputCopy
题目信息
题号
916E
时间限制
2.5 s
内存限制
256 MB
标签
数据结构
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。