Codeforces Round 253 (Div. 1)
D
Adam and Tree
Codeforces
2600
原题
← CE →
翻译中…

When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions:

翻译中…
  • There is no vertex that has more than two incident edges painted the same color.
  • For any two vertexes that have incident edges painted the same color (say, $*c*$), the path between them consists of the edges of the color $*c*$.
翻译中…

Not all tree paintings are equally good for Adam. Let's consider the path from some vertex to the root. Let's call the number of distinct colors on this path the cost of the vertex. The cost of the tree's coloring will be the maximum cost among all the vertexes. Help Adam determine the minimum possible cost of painting the tree.

翻译中…

Initially, Adam's tree consists of a single vertex that has number one and is the root. In one move Adam adds a new vertex to the already existing one, the new vertex gets the number equal to the minimum positive available integer. After each operation you need to calculate the minimum cost of coloring the resulting tree.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ ($1 ≤ *n* ≤ 10^{6}$) — the number of times a new vertex is added. The second line contains $*n*$ numbers $*p*_{*i*}$ ($1 ≤ *p*_{*i*} ≤ *i*$) — the numbers of the vertexes to which we add another vertex.

翻译中…

Output

翻译中…

Print $*n*$ integers — the minimum costs of the tree painting after each addition.

翻译中…

Note

翻译中…

The figure below shows one of the possible variants to paint a tree from the sample at the last moment. The cost of the vertexes with numbers 11 and 12 equals 3.

翻译中…

image

翻译中…

样例

Input #1
11
1 1 1 3 4 4 7 3 7 6 6
Output #1
1 1 1 1 1 2 2 2 2 2 3
InputCopy OutputCopy
题目信息
题号
442D
时间限制
2 s
内存限制
256 MB
标签
数据结构
树

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