coderforce Educational Codeforces Round 6 E.New Year Tree

来源:互联网 发布:windows ssh下载文件 编辑:程序博客网 时间:2024/06/16 09:46
E. New Year Tree
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.

The New Year tree is an undirected tree with n vertices and root in the vertex1.

You should process the queries of the two types:

  1. Change the colours of all vertices in the subtree of the vertex v to the colour c.
  2. Find the number of different colours in the subtree of the vertex v.
Input

The first line contains two integers n, m (1 ≤ n, m ≤ 4·105) — the number of vertices in the tree and the number of the queries.

The second line contains n integers ci (1 ≤ ci ≤ 60) — the colour of thei-th vertex.

Each of the next n - 1 lines contains two integersxj, yj (1 ≤ xj, yj ≤ n) — the vertices of thej-th edge. It is guaranteed that you are given correct undirected tree.

The last m lines contains the description of the queries. Each description starts with the integertk (1 ≤ tk ≤ 2) — the type of thek-th query. For the queries of the first type then follows two integersvk, ck (1 ≤ vk ≤ n, 1 ≤ ck ≤ 60) — the number of the vertex whose subtree will be recoloured with the colour ck. For the queries of the second type then follows integervk (1 ≤ vk ≤ n) — the number of the vertex for which subtree you should find the number of different colours.

Output

For each query of the second type print the integer a — the number of different colours in the subtree of the vertex given in the query.

Each of the numbers should be printed on a separate line in order of query appearing in the input.

Examples
Input
7 101 1 1 1 1 1 11 21 31 43 53 63 71 3 22 11 4 32 11 2 52 11 6 42 12 22 3
Output
234512
Input
23 301 2 2 6 5 3 2 1 1 1 2 4 5 3 4 4 3 3 3 3 3 4 61 21 31 42 52 63 73 84 94 104 116 126 137 147 157 168 178 1810 1910 2010 2111 2211 232 12 52 62 72 82 92 102 112 41 12 11 13 11 14 11 15 11 16 11 17 11 18 11 19 11 20 11 21 11 22 11 23 12 12 52 62 72 82 92 102 112 4
Output
613321235512211123

0 0
原创粉丝点击