|
||||||||||
Counting OffspringTime Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5154 Accepted Submission(s): 1662 Problem Description You are given a tree, it¡¯s root is p, and the node is numbered from 1 to n. Now define f(i) as the number of nodes whose number is less than i in all the succeeding nodes of node i. Now we need to calculate f(i) for any possible i. Input Multiple cases (no more than 10), for each case: The first line contains two integers n (0<n<=10^5) and p, representing this tree has n nodes, its root is p. Following n-1 lines, each line has two integers, representing an edge in this tree. The input terminates with two zeros. Output For each test case, output n integer in one line representing f(1), f(2) ¡ f(n), separated by a space. Sample Input
Sample Output
Author bnugong Source | ||||||||||
|