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

#LCA0000007. Truy vấn tổng trên cây con (Subtree Queries)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Truy vấn tổng trên cây con (Subtree Queries)

Subtree Queries

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

There is a tree of nn vertices rooted at vertex 11. Vertex ii stores an integer aia_i.

Process qq operations in order. 1 s x assigns xx to vertex ss (it does not add xx). 2 s asks for the sum of all values in the subtree rooted at ss, including vertex ss.

Each sum query uses all preceding assignments.

Input

  • The first line contains n,qn,q.
  • The second line contains a1,…,ana_1,\ldots,a_n.
  • The next n−1n-1 lines contain undirected edges ui,viu_i,v_i.
  • The last qq lines contain 1 s x or 2 s.

Output

For each type-2 query, print the subtree sum on its own line.

Subtasks

  • Subtask 1 (20 points): n≤30n\le30; q≤60q\le60; 1≤n,q≤2⋅1051\le n,q\le2\cdot10^5; 1≤ai,x≤1091\le a_i,x\le10^9.
  • Subtask 2 (30 points): n≤1000n\le1000; q≤3000q\le3000; 1≤n,q≤2⋅1051\le n,q\le2\cdot10^5; 1≤ai,x≤1091\le a_i,x\le10^9.
  • Subtask 3 (50 points): 1≤n,q≤2⋅1051\le n,q\le2\cdot10^5; 1≤ai,x≤1091\le a_i,x\le10^9.

Examples

Input

5 3
4 2 5 2 1
1 2
1 3
3 4
3 5
2 3
1 5 3
2 3

Output

8
10

Explanation

Vertex 33 has subtree {3,4,5}\{3,4,5\}, initially summing to 5+2+1=85+2+1=8. Assigning 33 to vertex 55 changes the sum to 1010.