You are given a rooted tree with $$$n$$$ vertices and $$$\ell$$$ leaves. The vertices are indexed $$$1 \ldots n$$$ and the root vertex is $$$1$$$. Exactly $$$k$$$ leaves $$$u_1, \ldots, u_k$$$ are chosen. Here, the root of the tree isn't considered a leaf, even if it has only one neighbor. What is the maximum cardinality of the set $$$$$$ \{ \mathrm{lca}(u_i, u_j) \mid 1 \le i, j \le k \}?$$$$$$ Here, $$$\mathrm{lca}(u, v)$$$ refers to the lowest common ancestor of vertices $$$u$$$ and $$$v$$$. Solve this problem for each $$$k$$$ in $$$1 \ldots \ell$$$, where $$$\ell$$$ is the number of leaves in the tree.
The first line of the input consists of a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices.
The second line consists of $$$n - 1$$$ integers $$$p_2, p_3, \ldots, p_n$$$ ($$$1 \le p_i \lt i$$$), denoting an edge between $$$p_i$$$ and $$$i$$$.
Let $$$\ell$$$ be the number of leaves in the tree.
Print $$$\ell$$$ integers on a single line, the $$$k$$$-th of which is the answer to the problem if exactly $$$k$$$ leaves are chosen.
7 1 1 2 4 2 2
1 3 5 6
| Название |
|---|


