시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB119817072.165%

문제

A monochrome tree is a tree in which each vertex is colored either white or black. The score of a monochrome tree is equal to the number of unordered vertex pairs $(u, v)$ such that:

  • Both vertices $u$ and $v$ are colored black.
  • $u$ is an ancestor of $v$, or $v$ is an ancestor of $u$.

You are given a rooted tree of $n$ vertices whose root vertex is $1$.

For each $k$ from $0$ to $n$ (inclusive), you may color the given tree in such a way that there are exactly $k$ black vertices and $n - k$ white vertices. Among all the possible colorings, we denote the lowest score of a coloring as $c_k$.

Find $c_k$ for all $0 \leq k \leq n$.

입력

The first line contains a single integer $n$, the number of vertices in the given tree. ($1 \leq n \leq 2 \times 10^5$).

The $i$-th line of the following $n-1$ lines contain a single integer $p_{i+1}$ ($1 \leq p_{i+1} \leq n$, $p_{i+1} \neq i+1$), meaning that the parent of vertex $i+1$ is $p_{i+1}$.

출력

On the first and only line, print $n+1$ integers, the $i$-th of which denotes $c_{i-1}$. ($1 \leq i \leq n+1$)

서브태스크

번호배점제한
120

$n \leq 20$

220

$n \leq 500$

360

No further constraints

예제 입력 1

3
1
1

예제 출력 1

0 0 0 2

예제 입력 2

3
3
1

예제 출력 2

0 0 1 3

노트

Vertex $x$ is an ancestor of vertex $y$ $(x \neq y)$ if there is a sequence of vertices $\{x=a_1, a_2, \ldots a_k=y\}$ where $a_i$ is a parent of $a_{i+1}$ ($1 \leq i \leq k-1$).

출처

University > KAIST > 2023 KAIST RUN Spring Contest C번

채점 및 기타 정보

  • 예제는 채점하지 않는다.