PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000316. Cây thay đổi giá trị (Dynamic Subtree Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cây thay đổi giá trị (Dynamic Subtree Sum)

Dynamic Subtree Sum

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected tree has nn vertices numbered from 11 to nn and is rooted at vertex 11. Initially, vertex vv has integer value ava_v.

The subtree rooted at vv consists of vv and every vertex whose path from root 11 passes through vv. The edges never change.

Process the following qq operations in input order:

  • 1 v x: assign xx to vertex vv (do not add xx).
  • 2 v: report the sum of current values of all vertices in the subtree rooted at vv.

Input

  • The first line contains integers n,qn,q, the number of vertices and operations, respectively.
  • The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n; the ii-th integer is the initial value of vertex ii.
  • Each of the next n−1n-1 lines contains integers u,wu,w, the endpoints of an undirected edge.
  • The last qq lines describe operations in execution order. If the first integer is 11, the line also contains vertex vv and its new value xx. If it is 22, the line contains only one more integer, the queried vertex vv.

Output

Print one integer per type-2 operation, in query order. If there are no type-2 operations, print nothing.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤2000001\le n,q\le 200000; −109≤ai,x≤109-10^9\le a_i,x\le10^9; 1≤i,u,w,v≤n1\le i,u,w,v\le n; The edges form an undirected tree without duplicate edges or loops. All operations are type 1 or 2. n,q≤100n,q\le100.
  • Subtask 2 (30 points): 1≤n,q≤2000001\le n,q\le 200000; −109≤ai≤109-10^9\le a_i\le10^9; 1≤i,u,w,v≤n1\le i,u,w,v\le n; The edges form an undirected tree without duplicate edges or loops. All operations are type 2.
  • Subtask 3 (50 points): 1≤n,q≤2000001\le n,q\le 200000; −109≤ai,x≤109-10^9\le a_i,x\le10^9; 1≤i,u,w,v≤n1\le i,u,w,v\le n; The edges form an undirected tree without duplicate edges or loops. All operations are type 1 or 2.

Example 1

Input

5 6
3 -2 4 7 -1
1 2
1 3
2 4
2 5
2 2
1 4 -5
2 2
2 1
1 2 10
2 2

Output

4
-8
-1
4

Explanation

Subtree 2 contains vertices 2, 4, 5, initially totaling −2+7−1=4-2+7-1=4. Assigning −5-5 to vertex 4 changes that sum to −8-8. The whole tree sums to 3−2+4−5−1=−13-2+4-5-1=-1. Assigning 10 to vertex 2 gives 10−5−1=410-5-1=4.

Example 2

Input

1 4
-8
2 1
1 1 0
1 1 0
2 1

Output

-8
0

Explanation

The only vertex is vertex 11, initially valued at −8-8. The first query returns −8-8. The next two operations both assign 00 to this vertex, so the second assignment changes nothing. The final query returns 00.