102631: [AtCoder]ABC263 B - Ancestor
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Score : $200$ points
Problem Statement
There are $N$ people, called Person $1$, Person $2$, $\ldots$, Person $N$.
The parent of Person $i$ $(2 \le i \le N)$ is Person $P_i$. Here, it is guaranteed that $P_i < i$.
How many generations away from Person $N$ is Person $1$?
Constraints
- $2 \le N \le 50$
- $1 \le P_i < i(2 \le i \le N)$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
$N$ $P_2$ $P_3$ $\dots$ $P_N$
Output
Print the answer as a positive integer.
Sample Input 1
3 1 2
Sample Output 1
2
Person $2$ is a parent of Person $3$, and thus is one generation away from Person $3$.
Person $1$ is a parent of Person $2$, and thus is two generations away from Person $3$.
Therefore, the answer is $2$.
Sample Input 2
10 1 2 3 4 5 6 7 8 9
Sample Output 2
9
Input
题意翻译
### 题目描述 有 $n$ 个人,第 $i$ 个人的上一代是 $p_i(p_i<i)$。 问第 $1$ 个人与第 $n$ 个人之间隔了几代。 ### 输入格式 第一行,一个整数 $n$。 第二行,$n-1$ 个整数,表示 $p_2,p_3,\cdots,p_n$。 ### 输出格式 输出答案。Output
得分:$200$分
部分
问题描述
有$N$个人,分别叫做Person $1$, Person $2$, $\ldots$, Person $N$。
Person $i$ $(2 \le i \le N)$的父母是Person $P_i$。在这里,可以保证$P_i < i$。
Person $1$离Person $N$有多少代?
部分
限制条件
$2 \le N \le 50$
$1 \le P_i < i(2 \le i \le N)$
输入均为整数。
部分
输入格式
输入按照以下格式从标准输入给出:
$N$
$P_2$ $P_3$ $\dots$ $P_N$
部分
输出格式
将答案作为一个正整数输出。
部分
样例输入1
3
1 2
部分
样例输出1
2
Person $2$是Person $3$的父母,因此离Person $3$有一代。
Person $1$是Person $2$的父母,因此离Person $3$有两代。
因此,答案为$2$。
部分
样例输入2
10
1 2 3 4 5 6 7 8 9
部分
样例输出2
9