#SGM0000086. Cây năm mới (New Year Tree)
Cây năm mới (New Year Tree)
New Year Tree
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem
Each vertex of a rooted tree has a color from 1 to 60. Support recoloring every vertex in a subtree with one color and querying the number of distinct colors in a subtree.
Input
The first line contains and . The second line contains the initial colors. The next lines contain the tree edges. Each of the following lines is one of:
1 v c: recolor every vertex in the subtree of with color .2 v: query the number of distinct colors in the subtree of .
The tree is rooted at vertex 1.
Output
For each operation of type 2, print the number of distinct colors.
Subtasks
Subtask 1 (20%)
- The tree size and number of operations are at most 20.
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- The tree size and number of operations are at most 2000.
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- .
- .
Example
Input
1 15
43
2 1
2 1
2 1
2 1
2 1
1 1 13
2 1
2 1
2 1
2 1
2 1
1 1 34
2 1
2 1
2 1
Output
1
1
1
1
1
1
1
1
1
1
1
1
1
Explanation
The tree contains only one vertex, so every query reports exactly one distinct color.