Monochrome Tree
Time limit2sMemory limit1024 MB
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 such that:
- Both vertices and are colored black.
- is an ancestor of , or is an ancestor of .
You are given a rooted tree of vertices whose root vertex is .
For each from to (inclusive), you may color the given tree so that there are exactly black vertices and white vertices. Among all such colorings, let be the lowest score. Find for all .
Input
The first line contains a single integer , the number of vertices in the tree ().
The -th of the following lines contains a single integer (, ), the parent of vertex .
Output
On the first and only line, print integers. The -th of them is ().
Hint
Vertex is an ancestor of vertex if there is a sequence of vertices where is a parent of ().