#P9864. A. Xcellent Tree Query Problem
A. Xcellent Tree Query Problem
A. Xcellent Tree Query Problem
Problem Description
Given a tree consisting of nodes. Each node initially have a color . You are given commands, each of them is one of the follows:
- : Cut the -th edge of the input.
- : For every currently connected with (that is, no edges lying on the simple path from to is cut), if , set to .
- : Count the number of currently connected with , that satisfy .
Input
The first line of the input contains two integers () and (). The second line contains integers (). Each of the following lines contains two integers (, ) - an edge of the tree. Each of the following lines contains one of the three commands listed above. It's guaranteed that no edges is cut twice or more. It's also guaranteed that in command of type and , , .
Output
For every command of type , output the answer in a single line.
Sample Input
10 19
1 2 3 4 5 6 7 8 9 10
1 2
2 3
3 4
4 5
4 6
5 7
5 8
1 9
9 10
3 4 1 10
3 8 3 4
2 9 9 10 1
3 4 1 10
3 2 8 10
1 4
3 8 1 10
3 7 7 8
2 5 5 7 9
3 7 9 10
2 1 1 2 3
3 1 3 3
1 1
3 1 3 3
2 10 3 9 4
3 1 4 4
2 3 3 5 9
3 3 6 10
3 3 6 6
Sample Output
10
2
10
1
3
2
2
5
3
3
4
1
Source
2023“钉耙编程”中国大学生算法设计超级联赛(7)