---
# System prepended metadata

title: 12574 - New Year
tags: [NTHUOJ]

---

# 12574 - New Year
## 題解:
只有跟Bob的parent同一個level的才能全加進答案裡,
以上的level最多只能加一次(如果存在的話)

**Note:** 同個level代表pi相同
## Code:
```c=1
#include <stdio.h>
#define MAXN 100005

int p[MAXN], cnt[MAXN];

int main(){
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++){
        scanf("%d", &p[i]);
        cnt[p[i]]++;
    }
    int f = p[p[n]], count = 1;
    while(f != -1){
        if(count == 1)
            ans += cnt[f];
        else
            ans++;
        f = p[f];
        count++;
    }
    ans++; // pi passed away
    printf("%d\n", ans);
    return 0;
}
```
###### tags: `NTHUOJ`