Monochrome Tree

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

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)(u, v) such that:

  • Both vertices uu and vv are colored black.
  • uu is an ancestor of vv, or vv is an ancestor of uu.

You are given a rooted tree of nn vertices whose root vertex is 11.

For each kk from 00 to nn (inclusive), you may color the given tree in such a way that there are exactly kk black vertices and nkn - k white vertices. Among all the possible colorings, we denote the lowest score of a coloring as c_kc\_k.

Find c_kc\_k for all 0kn0 \leq k \leq n.

입력

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

The ii-th line of the following n1n-1 lines contain a single integer p_i+1p\_{i+1} (1p_i+1n1 \leq p\_{i+1} \leq n, p_i+1i+1p\_{i+1} \neq i+1), meaning that the parent of vertex i+1i+1 is p_i+1p\_{i+1}.

출력

On the first and only line, print n+1n+1 integers, the ii-th of which denotes c_i1c\_{i-1}. (1in+11 \leq i \leq n+1)

힌트

Vertex xx is an ancestor of vertex yy (xy)(x \neq y) if there is a sequence of vertices x=a_1,a_2,a_k=y\\{x=a\_1, a\_2, \ldots a\_k=y\\} where a_ia\_i is a parent of a_i+1a\_{i+1} (1ik11 \leq i \leq k-1).