Problem 2998 --Colored Tree

2998: Colored Tree

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $0$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
There is a tree with vertex 1 as a root. All vertices of the tree are colored. 
Your task is to determine the number of sub-trees with exactly k distinct colors. 
There are two types of queries. 
1 u c : paint vertex u with color c. 
2 k : answer the query.
The first line of input contains an integer T (1 <= T <= 5) denoting the number of test cases. 
The first line of each test case contains two integers N and Q (1 <= N, Q <= 100000), the number of vertices in the given tree and the number of queries respectively. Each of the next N - 1 lines contains two integers u and v, representing that there exists an edge between vertex u and v. 
The next line contains N space-separated integers and the i-th integer denotes the color of vertex i. 
Then Q lines followed and each line consists of one of two types of queries.
For each query of type 2, output the answer in one line.
1
3 2
1 2
2 3
1 2 3
1 2 1
2 2
2

推荐代码 查看2998 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战

赛题来源/所属竞赛 2019 Multi-University Training Contest 4 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛