1 /**************************************************************
2 Problem: 1217
3 User: ZYBGMZL
4 Language: C++
5 Result: Accepted
6 Time:0 ms
7 Memory:1312 kb
8 ****************************************************************/
9
10 #include<cstdio>
11 #include<cstring>
12 #include<iostream>
13 using namespace std;
14 #define inf 0x3f3f3f3f
15
16 struct Edge{
17 int to,nxt;
18 Edge(int to=0,int nxt=0):
19 to(to),nxt(nxt){}
20 };
21
22 const int maxn=1005;
23
24 int n,cnt=0,ans=0,f[maxn],head[maxn];
25 Edge E[maxn<<1];
26
27 inline void a_ed(int from,int to){
28 E[++cnt]=Edge(to,head[from]); head[from]=cnt;
29 E[++cnt]=Edge(from,head[to]); head[to]=cnt;
30 }
31
32 void dfs(int no,int fa){
33 int mx=-inf,mi=inf;
34 for(int e=head[no];e;e=E[e].nxt){
35 int nt=E[e].to; if(nt==fa) continue;
36 dfs(nt,no);
37 mx=max(mx,f[nt]); mi=min(mi,f[nt]);
38 }
39 if(mx+mi<=3) f[no]=mi+1;
40 else f[no]=mx+1;
41 if(mx==-inf) f[no]=3;
42 if(f[no]==5){
43 f[no]=0;
44 ans++;
45 }
46 if(f[no]>=3&&fa==-1) ans++;
47 }
48
49 int main(){
50 scanf("%d",&n);
51 for(int i=2,to;i<=n;i++){
52 scanf("%d",&to);
53 a_ed(i,to);
54 }
55 dfs(1,-1);
56 printf("%d\n",ans);
57 return 0;
58 }