|
||||||||||
Colorful TreeTime Limit: 24000/12000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1040 Accepted Submission(s): 160 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
Sample Output
Source | ||||||||||
|