package main
import (
"io"
"os"
"strconv"
)
var parent []int
var val []int
var mx1 []int
var mx2 []int
var cnt1 []int
func calc(v int) int {
a := mx1[v]
if a < 0 {
return 0
}
b := mx2[v]
if cnt1[v] >= 2 {
b = a
}
if b+1 > a {
return b + 1
}
return a
}
func insertChild(p, childVal int) {
if childVal > mx1[p] {
mx2[p] = mx1[p]
mx1[p] = childVal
cnt1[p] = 1
} else if childVal == mx1[p] {
cnt1[p]++
} else if childVal > mx2[p] {
mx2[p] = childVal
}
}
func increaseChild(p, oldVal, newVal int) {
if newVal == oldVal {
return
}
oldMax := mx1[p]
if oldVal == oldMax {
if cnt1[p] > 1 {
mx2[p] = oldMax
}
mx1[p] = newVal
cnt1[p] = 1
} else {
if newVal > oldMax {
mx2[p] = oldMax
mx1[p] = newVal
cnt1[p] = 1
} else if newVal == oldMax {
cnt1[p]++
} else if newVal > mx2[p] {
mx2[p] = newVal
}
}
}
func main() {
data, _ := io.ReadAll(os.Stdin)
idx := 0
nextInt := func() int {
for idx < len(data) && (data[idx] < '0' || data[idx] > '9') {
idx++
}
x := 0
for idx < len(data) && data[idx] >= '0' && data[idx] <= '9' {
x = x*10 + int(data[idx]-'0')
idx++
}
return x
}
n := nextInt()
size := n + 2
parent = make([]int, size)
val = make([]int, size)
mx1 = make([]int, size)
mx2 = make([]int, size)
cnt1 = make([]int, size)
for i := 0; i < size; i++ {
mx1[i] = -1
mx2[i] = -1
}
out := make([]byte, 0, n*4)
nextID := 2
for step := 0; step < n; step++ {
p := nextInt()
x := nextID
nextID++
parent[x] = p
insertChild(p, 0)
if p != 1 {
oldv := val[p]
newv := calc(p)
if newv > oldv {
val[p] = newv
child := p
oldChild := oldv
newChild := newv
for {
par := parent[child]
if par == 0 {
break
}
increaseChild(par, oldChild, newChild)
if par == 1 {
break
}
oldp := val[par]
newp := calc(par)
if newp == oldp {
break
}
val[par] = newp
child = par
oldChild = oldp
newChild = newp
}
}
}
ans := 0
if mx1[1] >= 0 {
ans = mx1[1] + 1
}
out = strconv.AppendInt(out, int64(ans), 10)
if step+1 < n {
out = append(out, ' ')
}
}
out = append(out, '\n')
os.Stdout.Write(out)
}