CF930A.Peculiar apple-tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn inflorescences, numbered from 11 to nn . Inflorescence number 11 is situated near base of tree and any other inflorescence with number ii ( i>1 ) is situated at the top of branch, which bottom is pip_{i} -th inflorescence and p_{i}<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 aa -th inflorescence gets to pap_{a} -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 55 apples in same inflorescence in same time, only one will not be annihilated and if there are 88 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 nn ( 2<=n<=1000002<=n<=100000 ) — number of inflorescences.

Second line of input contains sequence of n1n-1 integer numbers p2,p3,...,pnp_{2},p_{3},...,p_{n} ( 1<=p_{i}<i ), where pip_{i} is number of inflorescence into which the apple from ii -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.

输入输出样例

  • 输入#1

    3
    1 1
    

    输出#1

    1
    
  • 输入#2

    5
    1 2 2 2
    

    输出#2

    3
    
  • 输入#3

    18
    1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4
    

    输出#3

    4
    

说明/提示

In first example Arcady will be able to collect only one apple, initially situated in 11 st inflorescence. In next second apples from 22 nd and 33 rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.

In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 22 nd inflorescence will roll down to 11 st (Arcady will collect it) and apples from 33 rd, 44 th, 55 th inflorescences will roll down to 22 nd. Two of them will annihilate and one not annihilated will roll down from 22 -nd inflorescence to 11 st one in the next second and Arcady will collect it.

首页