Problem8835--[yosupo] Tree - Dynamic Tree Vertex Add Path Sum

8835: [yosupo] Tree - Dynamic Tree Vertex Add Path Sum

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Given tree of $N$ vertices. Edges are $(u_i, v_i)$. Value $a_i$ is written on vertex $i$.
Process the following $Q$ queries in order. You can assume that the graph is always the tree while processing the queries.
- 0 $u$ $v$ $w$ $x$: Delete a edge $(u, v)$, and add $(w, x)$.
- 1 $p$ $x$: $a_p \gets a_p + x$
- 2 $u$ $v$: Print the sum of values of vertices of the path between $u$ and $v$ (inclusive).

Input

$N$ $Q$
$a_0$ $a_1$ ... $a_{N - 1}$
$u_0$ $v_0$
$u_1$ $v_1$
:
$u_{N - 2}$ $v_{N - 2}$
$\textrm{Query}_0$
$\textrm{Query}_1$
:
$\textrm{Query}_{Q - 1}$

Constraints

$1 \leq N, Q \leq 200,000$
$0 \leq a_i, x \leq 10^9$
$0 \leq p, u_i, v_i < N$
$(u_i, v_i)$ is tree.
for type 0 queries, there is a edge $(u, v)$.
The graph is always tree.

Sample 1 Input

5 7
1 10 100 1000 10000
0 1
1 2
2 3
1 4
2 0 3
1 1 100000
2 3 4
0 1 2 2 0
2 3 4
0 2 3 3 1
2 2 3

Sample 1 Output

1111
111110
111111
101111

HINT

相同题目:yosupo

Source/Category