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

#SRD0000092. Truy vấn nguyên thủy (Primitive Queries)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Truy vấn nguyên thủy (Primitive Queries)

Primitive Queries

Source: VNOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an undirected tree with nn vertices, vertex uu initially carries the integer CuC_u. Process QQ operations in input order.

There are two operation types:

  • 1 u v: count the distinct vertex values on the unique simple path from uu to vv, including both endpoints.
  • 2 x val: assign the value valval to vertex xx, replacing its old value (not adding to it).

Each type-1 answer must use the state obtained after all preceding assignments.

Input

  • The first line contains n,Qn,Q.
  • The second line contains nn initial values C1,…,CnC_1,\ldots,C_n.
  • Each of the next n−1n-1 lines contains endpoints u,vu,v of an undirected tree edge; the edges form a tree.
  • Each of the last QQ lines contains 1 u v or 2 x val.

Output

Print one integer for each type 1 operation: the number of distinct values on its queried path. Print nothing for type 2 operations.

Subtasks

  • Subtask 1 (50 points): Only type 1 operations occur.
  • Subtask 2 (50 points): No additional restrictions.

Complete conditions for all subtasks, subject to the tighter limits above: 1≤n,Q≤1051\le n,Q\le 10^5, 0≤Ci,val≤1090\le C_i,val\le 10^9, 1≤u,v,x≤n1\le u,v,x\le n.

Examples

Input

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

Output

5
3
4
3
3

Explanation

Initially the values at vertices 1,2,3,4,5,61,2,3,4,5,6 are 1,2,3,4,5,61,2,3,4,5,6.

  1. 1 5 6 follows path 5→2→1→3→65\to2\to1\to3\to6 with values 5,2,1,3,65,2,1,3,6, so output 5.
  2. 2 5 6 assigns value 66 to vertex 55.
  3. 1 1 5 has values 1,2,61,2,6, giving 3.
  4. 1 5 6 has values 6,2,1,3,66,2,1,3,6: four distinct values, giving 4.
  5. 2 1 6 assigns value 66 to vertex 11.
  6. 1 5 6 has values 6,2,6,3,66,2,6,3,6, giving 3.
  7. 1 2 6 has values 2,6,3,62,6,3,6, giving 3.