Universal Cup Judging System

Universal Cup

حد الوقت: 1.0 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

给定一棵有 $n$ 个顶点和 $\ell$ 个叶子节点的有根树。顶点编号为 $1 \dots n$,根节点为 $1$。从中恰好选择 $k$ 个叶子节点 $u_1, \dots, u_k$。在此处,树的根节点不被视为叶子节点,即使它只有一个邻居。集合 $$\{\text{lca}(u_i, u_j) \mid 1 \le i, j \le k\}$$ 的最大基数是多少?

这里,$\text{lca}(u, v)$ 指的是顶点 $u$ 和 $v$ 的最近公共祖先。对于 $1 \dots \ell$ 中的每一个 $k$ 求解此问题,其中 $\ell$ 是树中叶子节点的数量。

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 2 \cdot 10^5$),表示顶点的数量。 第二行包含 $n-1$ 个整数 $p_2, p_3, \dots, p_n$ ($1 \le p_i < i$),表示 $p_i$ 和 $i$ 之间存在一条边。

输出格式

设 $\ell$ 为树中叶子节点的数量。 在一行中输出 $\ell$ 个整数,其中第 $k$ 个整数表示恰好选择 $k$ 个叶子节点时的答案。

样例

输入 1

7
1 1 2 4 2 2

输出 1

1 3 5 6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.