题目简单,不多解释。

Code:

#include<cstdio>
#include<queue>
using namespace std;
const int maxn = 1000000 + 3;
int head[maxn], to[maxn], nex[maxn], cnt, dep[maxn], numv[maxn];
queue<int>Q;
inline void add_edge(int u,int v)
{
nex[++cnt] = head[u], head[u] = cnt, to[cnt] = v;
}
int main()
{
//freopen("input.in","r",stdin);
int n;
scanf("%d",&n);
for(int i = 2;i <= n; ++i)
{
int a; scanf("%d",&a);
add_edge(a,i);
}
Q.push(1); dep[1] = 1; numv[1] = 1;
while(!Q.empty())
{
int u = Q.front(); Q.pop();
for(int v = head[u]; v ; v = nex[v])
{
dep[to[v]] = dep[u] + 1;
++numv[dep[to[v]]];
Q.push(to[v]);
}
}
int ans = 0;
for(int i = 1;i <= 1000000; ++i)
{
if(numv[i] % 2 == 1) ++ans;
}
printf("%d",ans);
return 0;
}

Codeforces Round #468 (Div. 2 )D. Peculiar apple-tree_BFS的更多相关文章

  1. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)D. Peculiar apple-tree

    In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity ...

  2. Codeforces Round #468 Div. 2题解

    A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup

    The last stage of Football World Cup is played using the play-off system. There are n teams left in ...

  4. Codeforces Round #468 Div. 1

    D:首先考虑如果给定白棋位置,如何判断胜负.黑棋获胜需要四个方向都有能贴上白棋的棋子.由于每一轮都必须移动,显然先对平面黑白染色一下,只有与白棋所在格异色的黑棋才需要考虑.考虑让一个黑棋去贴上白棋某个 ...

  5. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)

    A.B都是暴力搞一搞. A: #include<bits/stdc++.h> #define fi first #define se second #define mk make_pair ...

  6. codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)

    题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率. 用map记录每个字母出现的位置.对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数 ...

  7. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work

    Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some v ...

  8. Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. Friends Meeting

    Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the ...

  9. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

随机推荐

  1. 查看Linux系统版本信息的几种方法

    一.查看Linux内核版本命令(两种方法): 1.cat /proc/version 2.uname -a 二.查看Linux系统版本的命令(3种方法): 1.lsb_release -a,即可列出所 ...

  2. [SCOI2016]萌萌哒(倍增+并查集)

    当区间\([a,b]\)和\([c,d]\)对应相等时. 我们把两个区间对应位置上的数所在并查集合并. 最后并查集的数量为\(num\)答案就是\(9*10^num\)因为是个数,不能有前置\(0\) ...

  3. 训练1-R

    给出一个长度为N的数组,进行Q次查询,查询从第i个元素开始长度为l的子段所有元素之和. 例如,1 3 7 9 -1,查询第2个元素开始长度为3的子段和,1 {3 7 9} -1.3 + 7 + 9 = ...

  4. [luogu3952 noip2017] 逛公园 (计数dp+最短路)

    传送门 Description Input Output 输出文件包含 T 行,每行一个整数代表答案. Sample Input 2 5 7 2 10 1 2 1 2 4 0 4 5 2 2 3 2 ...

  5. preload、prefetch的认识

    预加载 现在的网络情况虽然很乐观,但是 defer和async 当浏览器碰到 script 脚本的时候: <script src="script.js"></sc ...

  6. ORM框架 SQLAlchemy

    什么是ORM 使用关系对象映射进行数据库操作. 将对象转换成SQL,然后使用数据API执行SQL并获取执行结果. 分类 -DB first 手动创建数据库和表,自动生成类 -code first 手动 ...

  7. SQL-Oracle存储过程-循环A表,向B表插入数据

    --存储过程,查询A表,向B表插入数据 create or replace procedure prc_sg_sjtj_config(p_flag out varchar2) IS BEGIN FOR ...

  8. iOS相册实现与AssetsLibrary框架使用

    概述 在iOS中如果想要获取手机相册里面的图片或者视频的话就要用到系统自带的AssetsLibrary框架,AssetsLibrary.framework中包含以下文件 #import <Ass ...

  9. Android Otto调研

    这两天对Otto进行了一个简单的调研,发现官网特别简单差点儿没东西,github上给的sample也不是非常好.网上的技术博客也差点儿千篇一律,我就把自己的心得体会写下来吧,如有缘者看见望其少走弯路. ...

  10. Unity3D摄像机尾随人物

    这里的镜头主要是从人物的背后尾随的. 首先新建一个C#脚本,命名为MyFollow,然后把下面代码粘贴进去.保存: using UnityEngine; using System.Collection ...