Codeforces Round 430 (Div. 2)
E
Nikita and game
Codeforces
2800
原题
← D→
翻译中…

Nikita plays a new computer game. There are $*m*$ levels in this game. In the beginning of each level a new class appears in the game; this class is a child-class of the class $*y*_{*i*}$ (and $*y*_{*i*}$ is called parent-class for this new class). Thus, the classes form a tree. Initially there is only one class with index $1$.

翻译中…

Changing the class to its neighbour (child-class or parent-class) in the tree costs $1$ coin. You can not change the class back. The cost of changing the class $*a*$ to the class $*b*$ is equal to the total cost of class changes on the path from $*a*$ to $*b*$ in the class tree.

翻译中…

Suppose that at $*i*$ -th level the maximum cost of changing one class to another is $*x*$. For each level output the number of classes such that for each of these classes there exists some other class $*y*$, and the distance from this class to $*y*$ is exactly $*x*$.

翻译中…

Input

翻译中…

First line contains one integer number $*m*$ — number of queries ($1 ≤ *m* ≤ 3·10^{5}$).

翻译中…

Next $*m*$ lines contain description of queries. $*i*$ -th line ($1 ≤ *i* ≤ *m*$) describes the $*i*$ -th level and contains an integer $*y*_{*i*}$ — the index of the parent-class of class with index $*i* + 1$ ($1 ≤ *y*_{*i*} ≤ *i*$).

翻译中…

Output

翻译中…

Suppose that at $*i*$ -th level the maximum cost of changing one class to another is $*x*$. For each level output the number of classes such that for each of these classes there exists some other class $*y*$, and the distance from this class to $*y*$ is exactly $*x*$.

翻译中…

样例

Input #1
4
1
1
2
1
Output #1
2
2
2
3
InputCopy OutputCopy
Input #2
4
1
1
2
3
Output #2
2
2
2
2
InputCopy OutputCopy
题目信息
题号
842E
时间限制
2 s
内存限制
256 MB
标签
二分
DFS 及类似
分治
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。