F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Colored Tree

Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 279    Accepted Submission(s): 49


Problem Description
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.
 

Input
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.
 

Output
For each query of type 2, output the answer in one line.
 

Sample Input
1 3 2 1 2 2 3 1 2 3 1 2 1 2 2
 

Sample Output
2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 09:14:17, Gzip enabled