CF1056D.Decorate Apple Tree

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

阿卡迪的花园里有一棵苹果树。这棵树可以表示为一组由树枝连接的节点,使得任意两个节点之间都恰好存在一条路径。节点编号从 11 到 nn,其中节点 11 被称为根节点。

节点 vv 的子树是指所有满足“从 uu 到根节点的路径必经过 vv”的节点 uu 构成的集合。注意:vv 自身也属于其自身的子树。

叶子节点是指其子树中恰好包含一个节点的节点。

新年将至,阿卡迪打算装饰这棵树。他将在每个叶子节点上放置一个某种颜色的灯泡,然后统计“快乐节点”的数量。一个节点 tt 被称为快乐节点,当且仅当其子树内所有灯泡的颜色互不相同。

阿卡迪关心如下问题:对每个 k=1,2,…,nk = 1, 2, \dots, n,要使快乐节点的数量不少于 kk,所需的最少颜色种类数是多少?

输入格式

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the number of junctions in the tree.

The second line contains n−1n - 1 integers p2p_2, p3p_3, ..., pnp_n (1≤pi<i1 \le p_i \lt i), where pip_i means there is a branch between junctions ii and pip_i. It is guaranteed that this set of branches forms a tree.

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 表示树中节点的数量。

第二行包含 n−1n - 1 个整数 p2p_2, p3p_3, ..., pnp_n(1≤pi<i1 \le p_i \lt i),其中 pip_i 表示节点 ii 与节点 pip_i 之间存在一条边。保证这些边构成一棵树。

输出格式

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.

输出 nn 个整数。其中第 ii 个整数应为使得快乐交叉点数量至少为 ii 所需的最少颜色数。

输入输出样例

  • 输入#1

    3
    1 1

    输出#1

    1 1 2
  • 输入#2

    5
    1 1 3 3

    输出#2

    1 1 1 2 3

说明/提示

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.

在第一个例子中,当 k=1k = 1 和 k=2k = 2 时,我们只能使用一种颜色:结点 22 和 33 将是快乐的。当 k=3k = 3 时,必须在结点上安装不同颜色的灯泡,才能使所有结点都快乐。

在第二个例子中,当 k=4k = 4 时,例如可将颜色为 11 的灯泡安装在结点 22 和 44 上,并将颜色为 22 的灯泡安装在结点 55 上。此时,快乐的结点为索引为 22、33、44 和 55 的结点。

输入解题思路,AI测评打分。不知道怎么写?

首页