|
||||||||||
Harry and Christmas treeTime Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1248 Accepted Submission(s): 316 Problem Description 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. Input 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$. Output 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. Sample Input
Sample Output
Hint Make your program running as fast as possible. Source | ||||||||||
|