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

Colorful Tree

Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1015    Accepted Submission(s): 159


Problem Description
As we all know, frogs live on trees and have different colors.

$N$ frogs are living on a tree. The tree consists of $N$ nodes with node $1$ as the root, each frog occupies a node.

Frogs have different colors, and can change colors as they like. On each day, all the frogs living on a certain sub-tree will change its color. The root of the sub-tree, and the color they change to, is given to the frog king.

As the frog king, sometimes he may wonder, how many different colors of frog are there in a certain sub-tree? It turns to you to solve the problem for the king.
 

Input
First line contains an integer $T$, which indicates the number of test cases.

Every test case begins with an integers $N$, which is the numbers of nodes in the tree.

The following $N - 1$ lines describe the edges of the tree, and every line is formatted as '$u\ v$', which indicates there is a edge between node $u$ and node $v$.

The next line contains $N$ intergers, $c_1$, $c_2$, $\cdots$, $c_N$, and $c_i$ is the initial color of the frog living at node $i$.

Then a number $M$ follows, which indicates the number of queries, and following $M$ lines describe the quries as format bellow.



$\cdot$ $1 \leq T \leq 100$.

$\cdot$ For 85% data, $1 \leq N, M \leq 1000$.

$\cdot$ for 100% data, $1 \leq N, M \leq 10^5$.

$\cdot$ for every node, $1 \leq c_i \leq N$.

$\cdot$ for every edge, $1 \leq u, v \leq N$.

$\cdot$ for every query, $1 \leq u, c \leq N$.

 

Output
For every test case, you should output "Case #x:" first,
where $x$ indicates the case number and counts from $1$.

Then for each query operation, output the number of different colors.
 

Sample Input
1 5 1 2 1 3 2 5 2 4 1 2 3 4 5 6 1 1 0 4 2 1 1 1 2 0 2 3 1 2
 

Sample Output
Case #1: 5 4 2 1
 

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-05-07 06:06:33, Gzip enabled