Under construction

Still being built. Things may change

Monochrome Tree

Time limit2sMemory limit1024 MB

Summary
For each k from 0 to n, find the fewest ancestor-descendant pairs of black vertices when exactly k vertices of a rooted tree are colored black.
Level

Hard8 of 10

Topics
Tree, Dynamic programming
Solved
No attempts yet

Problem

A monochrome tree is a tree in which each vertex is colored either white or black. The score of a monochrome tree is 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 so that there are exactly kk black vertices and n−kn - k white vertices. Among all such colorings, let ckc_k be the lowest score. Find ckc_k for all 0≤k≤n0 \leq k \leq n.

Input

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

The ii-th of the following n−1n-1 lines contains a single integer pi+1p_{i+1} (1≤pi+1≤n1 \leq p_{i+1} \leq n, pi+1≠i+1p_{i+1} \neq i+1), the parent of vertex i+1i+1.

Output

On the first and only line, print n+1n+1 integers. The ii-th of them is ci−1c_{i-1} (1≤i≤n+11 \leq i \leq n+1).

Hint

Vertex xx is an ancestor of vertex yy (x≠y)(x \neq y) if there is a sequence of vertices {x=a1,a2,…ak=y}\{x=a_1, a_2, \ldots a_k=y\} where aia_i is a parent of ai+1a_{i+1} (1≤i≤k−11 \leq i \leq k-1).

Examples2

  1. Example 1

    Input
    3
    1
    1
    
    Expected output
    0 0 0 2
    
  2. Example 2

    Input
    3
    3
    1
    
    Expected output
    0 0 1 3