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

Harry and Christmas tree

Time 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
5 3 3 1 4 1 2 3 5 1 1 9 4 6 4 6
 

Sample Output
2 0 0 1 0
 

Hint

Make your program running as fast as possible.
 

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-11-22 12:04:33, Gzip enabled