当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5574:Colorful Tree

题目描述
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.
输入解释
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$.

输出解释
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.
输入样例
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
输出样例
Case #1:
5
4
2
1
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5574

最后修改于 2020-10-25T23:23:53+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
24000/12000MS(Java/Others) 131072/131072K(Java/Others)