Logo
(追記) (追記ここまで)

15210번 - Counterspells 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB3510840.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:

  • A vertex is white if and only if it has a black son.

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:

  • $add(v)$ -- Add a new black vertex to the tree as a son of vertex $v$. Then invert colors of some (possibly zero, possibly all) vertices in the tree so that the resulting tree is well-colored.

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.

제한

예제 입력 1

5
0
1
2
1
3

예제 출력 1

1
2
3
2
2

힌트

The situation after each operation looks like this (vertices inverted during previous operation are highlighted):

출처

Camp > Czech, Polish and Slovak Preparation Camp > CPSPC 2017 3-2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /