CF930A.Peculiar apple-tree
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
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 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 p__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 a-th inflorescence gets to p__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 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.
在阿尔卡季的花园里,生长着一棵奇特的苹果树,每年只结果一次。其独特性体现在以下方面:树上共有 n 个花序,编号从 1 到 n。编号为 1 的花序位于树干基部;而对任意其他编号为 i(i>1)的花序,它位于某一分枝的顶端,该分枝的底端连接的是编号为 pi 的花序,且满足 pi<i。
当果树开始结果时,每个花序中恰好出现一个苹果。苹果一出现,便立即沿树枝向树干基部滚动。每一秒,除位于第 1 号花序中的苹果外,其余所有苹果均沿树枝向下滚动一个单位(即从第 a 号花序滚至第 pa 号花序)。当苹果滚入第 1 号花序的瞬间,阿尔卡季会立即将其采摘。这棵树的第二个独特之处在于:一旦有两个苹果同时位于同一花序中,它们便会相互湮灭。这种湮灭作用发生在所有苹果对之间——例如,若同一时刻同一花序中有 5 个苹果,则其中 4 个将被湮灭,仅剩 1 个;若共有 8 个苹果,则全部湮灭。因此,在任意时刻,每个花序中至多只存在一个苹果。
请帮助阿尔卡季计算:在一个收获季中,他能从第 1 号花序中采集到多少个苹果?
输入格式
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 _p_2, _p_3, ..., p__n (1 ≤ p__i < i), where p__i is number of inflorescence into which the apple from i-th inflorescence rolls down.
输入的第一行包含一个整数 n(2≤n≤100000)——花序的数量。
输入的第二行包含 n−1 个整数 p2,p3,…,pn(1≤pi<i),其中 pi 表示第 i 个花序上的苹果滚落至的花序编号。
输出格式
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.
输出一行,包含一个整数:Arcady 在一次收获中能从第一簇花序上采集到的苹果数量。
输入输出样例
输入#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 1st inflorescence. In next second apples from 2nd and 3rd 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 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
在第一个例子中,阿尔卡季只能收集一个苹果,即最初位于第 1 个花序上的苹果。下一秒,第 2 和第 3 个花序上的苹果将滚落并相互湮灭,阿尔卡季无法收集它们。
在第二个例子中,阿尔卡季能够收集 3 个苹果。第一个是最初位于第 1 个花序上的苹果;第二秒时,第 2 个花序上的苹果将滚落到第 1 个花序(阿尔卡季将收集它),而第 3、第 4 和第 5 个花序上的苹果将滚落到第 2 个花序——其中两个将相互湮灭,剩下一个未湮灭的苹果将在下一秒从第 2 个花序滚落到第 1 个花序,阿尔卡季将收集它。
输入解题思路,AI测评打分。不知道怎么写?