|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||1024 MB||21||4||3||25.000%|
Magic: The Gathering card game has an interesting game mechanic of casting and countering spells. We are not going to explain it here, as it's quite complex and not necessary to solve this task. However, if you are a MtG player, you may see how this task is related to the spell countering mechanic.
For each rooted tree there is a unique way of coloring its vertices by two colors (black and white) satisfying the following constraint:
Uniqueness of this coloring can be easily proven by induction. We will call a tree well-colored if it's colored in this way.
We start with a rooted tree consisting of one black vertex (the root) and do the following operation $n$-times:
For each operation, we want to know how many vertices are inverted during this operation.
The root of the tree is numbered $0$, other vertices are numbered $1, 2, \dots, n$ in the order they are added to the tree.
The first line of the input contains a single integer $n$ ($1 \leq n \leq 200000$) -- number of vertex additions.
$n$ lines follow, $i$-th of them containing number $v_i$ -- ID of father of vertex added in $i$-th operation. It's guaranteed that vertex $v_i$ already exists before $i$-th operation, that is $v_i < i$.
For each operation output one line containing number of vertices whose colors will be inverted during this operation.
5 0 1 2 1 3
1 2 3 2 2
The situation after each operation looks like this (vertices inverted during previous operation are highlighted):