In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i > 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi < i.
Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.
Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
First line of input contains single integer number n (2 ≤ n ≤ 100 000) — number of inflorescences.
Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≤ pi < i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
3 1 1
1
5 1 2 2 2
3
18 1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
4
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#include<vector>
#define bug(x) printf("%d***\n",x)
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
vector<int> edge[maxn];
/*
忽略了过程,只是通过状态,直接告诉我们结果
真的,太牛了,我还纠结在细节,相邻的点
我们怎么记录,怎么判断,怎么做,还是菜啊
*/
int num[maxn];//某一层的苹果树
void dfs(int now,int floor){//建树,统计层次
num[floor]++;
for(int i=0;i<edge[now].size();i++){
int v=edge[now][i];
dfs(v,floor+1);
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=2;i<=n;i++){
int tmp;
scanf("%d",&tmp);
edge[tmp].push_back(i);
}
dfs(1,1);
int ans=0;
for(int i=1;i<=n;i++){
if(num[i]%2)
ans++;
}
printf("%d\n",ans);
return 0;
}