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

建议使用的浏览器:

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

5156:Harry and Christmas tree

题目描述
In Christmas Day, Harry got a Christmas tree. The tree has n nodes. And you can assume the tree rooted at node 1. Harry found that there are some gifts with different colors on some nodes. Then Harry began to count the gifts on the tree. Every time Harrty counted a gift, he written down a pair (a, b) on the paper. Where a indecates which node this gift located, and b indecates the color of this gift. After Harry finished all his counting, for each node x, he wanted to know the number of different kinds of colors that all gifts located on the subtree rooted at node x had.
输入解释
There are several test cases,you should process to the end of file.
For each test case, there are two integers n m on the first line, n indecates the number of the nodes, m indecates the number of countings. $1 \leq n \leq 50000, 1 \leq m \leq 500000$
The next following n-1 lines. Each line contains two integers a b, it means there is an edge between a and b. $1 \leq a, b \leq n, a \neq b$.
The next following m lines. Each line contains two integers a b, indecates the countings. $1 \leq a \leq n, 1 \leq b \leq 100000$.
输出解释
For each test case output one line contains n numbers, where a[i] indecates the number of different kinds of colors that all gifts located on the subtree rooted at node i had.
输入样例
5 3
3 1
4 1
2 3
5 1
1 9
4 6
4 6
输出样例
2 0 0 1 0
提示
Make your program running as fast as possible.
来自杭电HDUOJ的附加信息
Recommend heyang

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

题目来源 BestCoder Round #25

源链接: HDU-5156

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

共提交 0

通过率 --%
时间上限 内存上限
5000/2500MS(Java/Others) 65536/65536K(Java/Others)