codeforces 1056 D. Decorate Apple Tree (简单dfs)

D. Decorate Apple Tree

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is one apple tree in Arkady's garden. It can be represented as a set of junctions connected with branches so that there is only one way to reach any junctions from any other one using branches. The junctions are enumerated from 11 to nn, the junction 11 is called the root.

A subtree of a junction vv is a set of junctions uu such that the path from uu to the root must pass through vv. Note that vv itself is included in a subtree of vv.

A leaf is such a junction that its subtree contains exactly one junction.

The New Year is coming, so Arkady wants to decorate the tree. He will put a light bulb of some color on each leaf junction and then count the number happy junctions. A happy junction is such a junction tt that all light bulbs in the subtree of tt have different colors.

Arkady is interested in the following question: for each kk from 11 to nn, what is the minimum number of different colors needed to make the number of happy junctions be greater than or equal to kk?

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of junctions in the tree.

The second line contains n−1n−1 integers p2p2, p3p3, ..., pnpn (1≤pi<i1≤pi<i), where pipi means there is a branch between junctions ii and pipi. It is guaranteed that this set of branches forms a tree.

Output

Output nn integers. The ii-th of them should be the minimum number of colors needed to make the number of happy junctions be at least ii.

Examples

input

Copy

3
1 1

output

Copy

1 1 2 

input

Copy

5
1 1 3 3

output

Copy

1 1 1 2 3 

Note

In the first example for k=1k=1 and k=2k=2 we can use only one color: the junctions 22 and 33 will be happy. For k=3k=3 you have to put the bulbs of different colors to make all the junctions happy.

In the second example for k=4k=4 you can, for example, put the bulbs of color 11 in junctions 22 and 44, and a bulb of color 22 into junction 55. The happy junctions are the ones with indices 22, 33, 44 and 55 then.

 

有一颗树,可以往节点上挂灯泡(有很多种颜色),定义一个happy节点:这颗节点子树的所有节点所挂的灯泡颜色不同

现在问你有1到n个happy节点,分别需要最小多少种颜色来装饰灯泡

显然直接找每个节点的叶子节点个数,如果1到叶子节点个数就全都是1,然后就是剩下来的叶子节点最少的个数节点

所以直接dfs一下,f[i]代表i为节点的子树下有多少个叶子节点,排一下序直接输出即可

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值