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

#FT0000177. Lan truyền giá trị trên cây (Propagating Tree)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Lan truyền giá trị trên cây (Propagating Tree)

Propagating Tree

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected tree has NN vertices numbered 11 through NN and is rooted at vertex 11. Vertex ii initially holds aia_i. Process QQ commands in order. Command 1 x val adds valval to vertex xx, subtracts valval from its children, adds it to grandchildren, and keeps alternating signs throughout the subtree: vertex vv in the subtree of xx receives (−1)dist(x,v)val(-1)^{dist(x,v)}val. Command 2 x prints the current value at vertex xx. Updates accumulate, and values may become negative.

Input

The first line contains N,QN,Q; the second has NN initial values a1,…,aNa_1,\ldots,a_N. The next N−1N-1 lines describe an undirected tree. The last QQ lines are either 1 x val or 2 x.

Output

For every type-2 command print the current value of the specified vertex on its own line. Type-1 commands produce no output.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 1≤Q≤1001\le Q\le 100; 1≤ai≤10001\le a_i\le1000; exactly N−1N-1 undirected edges connecting vertices 1..N1..N into one tree rooted at 1; every command is 1 x val with 1≤x≤N1\le x\le N, 1≤val≤10001\le val\le1000, or 2 x with 1≤x≤N1\le x\le N; at least one 2.
  • Subtask 2 (30 points): 1≤N≤30001\le N\le 3000; 1≤Q≤50001\le Q\le 5000; 1≤ai≤10001\le a_i\le1000; exactly N−1N-1 undirected edges connecting vertices 1..N1..N into one tree rooted at 1; every command is 1 x val with 1≤x≤N1\le x\le N, 1≤val≤10001\le val\le1000, or 2 x with 1≤x≤N1\le x\le N; at least one 2.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Q≤2000001\le Q\le 200000; 1≤ai≤10001\le a_i\le1000; exactly N−1N-1 undirected edges connecting vertices 1..N1..N into one tree rooted at 1; every command is 1 x val with 1≤x≤N1\le x\le N, 1≤val≤10001\le val\le1000, or 2 x with 1≤x≤N1\le x\le N; at least one 2.

Examples

Example 1

Input

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

Output

3
3
0

Explanation

  1. 1 2 3: signed changes on affected vertices: 2:+3, 5:-3, 4:-3. New values by vertex order: [1, 5, 1, -2, -1]. No output.
  2. 1 1 2: signed changes on affected vertices: 1:+2, 3:-2, 2:-2, 5:+2, 4:+2. New values by vertex order: [3, 3, -1, 0, 1]. No output.
  3. 2 1: current value at vertex 1 is 3.
  4. 2 2: current value at vertex 2 is 3.
  5. 2 4: current value at vertex 4 is 0.

Example 2

Input

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

Output

6
-4
-2
4

Explanation

  1. 1 2 5: signed changes on affected vertices: 2:+5, 3:-5, 4:+5. New values by vertex order: [1, 6, -4, 6]. No output.
  2. 2 2: current value at vertex 2 is 6.
  3. 2 3: current value at vertex 3 is -4.
  4. 1 1 2: signed changes on affected vertices: 1:+2, 2:-2, 3:+2, 4:-2. New values by vertex order: [3, 4, -2, 4]. No output.
  5. 2 3: current value at vertex 3 is -2.
  6. 2 4: current value at vertex 4 is 4.