Holi And Tree

0

0 votes
Dynamic Programming, Algorithms, Medium-Hard, Depth-first search, Dp, Dynamic programming
Problem

This Holi you need to color the trees.There is a tree having N nodes with 1 as the root.A valid tree is defined as X-specific:

  • Every node except the leaf node has exactly X children. Here children means immediate children.

enter image description here

Your task is to compute the minimum number of nodes he should remove from the tree to make the tree X-specific. Find this for all X ranging from 1 to N).

Note: You can remove the nodes which are currently leafs in a single step

Constraints

1N105

Input

The first line contains one integer N .

The next N−1 lines contains two integers u and v denoting that there is an edge between them.

Output

Print N lines containing the answer.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For X=1 remove nodes 2,3,5.

For X=2 remove node 2.

For X=3 remove node 5,6

For X=4,5,6 remove all the nodes except root

Editor Image

?