#D. TheBigFatDuck play Game

    传统题 1000ms 256MiB

TheBigFatDuck play Game

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Background

TheBigFatDuck: This class is too easy, there's nothing interesting to listen to. Hey, what are you playing? It looks fun.

TheHamster: I'm playing a new game called Tree Game. Do you want to join me for a PVP match?

TheBigFatDuck: Sure.

Description

There is a rooted tree with nn nodes, indexed from 11 to nn. Node 11 is the root. For a node vv (v2)(v ≥ 2), its parent is fvf_v.

The rules of this game are as follows:

  • Initially, each node has a coin, and node 11 has a chess piece.
  • The game is played in turns, with TheHamster going first and TheBigFatDuck going second.
  • In each round:
    • If there is a coin on the node where the chess piece is located (In the following text, we will use xx to represent this node), the current player collects the coin and ends the round.
    • If there is no coin on the node xx:
      • If some of xx's child nodes have coins, the current player chooses one of those child nodes, moves the chess piece there, and ends the round.
      • If none of xx's child nodes have coins, the current player moves the chess piece to the parent node of xx and ends the round. If there is no parent, i.e. x=1x = 1, the game ends.

Both TheBigFatDuck and TheHamster play this game using optimal strategies, which means they always aim to collect coins as much as possible. The task is to determine the maximum number of coins that TheHamster can get.

Format

Input

The first line contains an integer nn, representing the number of nodes in the tree. (1n105)(1 \le n \le 10^5)

The second line contains n1n-1 integers fuf_u (2un)(2 \le u \le n), representing the parent of node uu.

Output

One line containing a single integer, representing the maximum number of coins that TheHamster can get.

Sample

10
1 2 3 4 5 6 7 8 9
10
5
1 2 3 1
2
10
1 1 3 1 3 6 7 6 6
5

Limitations

1 second, 128 MB


TheHamster: I won, hahaha.

Teacher: Hamster, stand up and solve this problem.

TheHamster pushed up his round glasses and looked at the teacher with big curious eyes. She secretly glanced at TheBigFatDuck and lowered her head.

TheBigFatDuck's face showed a smile, and then he raised his hand and stood up: Teacher, I know how to solve this problem. Let me help her.

2023安徽大学ICPC集训队排位选拔赛 - Round1

未参加
状态
已结束
规则
ACM/ICPC
题目
6
开始于
2023-6-3 8:00
结束于
2023-6-3 12:00
持续时间
4 小时
主持人
参赛人数
29