#605
Unrated
Subtree Activation
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

For the New Year celebration, Bessie and her friends have constructed a giant tree with many glowing ornaments. Bessie has the ability to turn the ornaments on and off through remote control. Before the sun rises, she wants to toggle some of the ornaments in some order (possibly toggling an ornament more than once) such that the tree starts and ends with no ornaments on. Bessie thinks the tree looks cool if the set of activated ornaments is exactly a subtree rooted at some vertex. She wants the order of ornaments she toggles to satisfy the property that, for every subtree, at some point in time it was exactly the set of all turned on ornaments. Additionally, it takes energy to switch on and off ornaments, and Bessie does not want to waste energy, so she wants to find the minimum number of toggles she can perform.

Formally, you have a tree with vertices labeled 1N1\dots N (2N21052\le N\le 2\cdot 10^5) rooted at 11. Each vertex is initially inactive. In one operation, you can toggle the state of a single vertex from inactive to active or vice versa. Output the minimum possible length of a sequence of operations satisfying both of the following conditions:

Define the subtree rooted at a vertex rr to consist of all vertices vv such that rr lies on the path from 11 to vv inclusive. For every one of the NN subtrees of the tree, there is a moment in time when the set of active vertices is precisely those in that subtree. Every vertex is inactive after the entire sequence of operations.

입력

The first line contains NN.

The second line contains p2pNp_2 \dots p_N (1pi<i1\le p_i<i), where pip_i denotes the parent of vertex ii in the tree.

출력

Output the minimum possible length.

예제 입력 1

3
1 1

예제 출력 1

6

점수

Inputs 2-3: N8N \le 8Inputs 4-9: N40N \le 40Inputs 10-15: N5000N \le 5000Inputs 16-21: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.