题目简单,不多解释。

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. centos7编译安装mysql5.6

    先安装如下依赖包: $ yum -y install make gcc-c++ cmake bison-devel  ncurses-devel 下载MySQL5.6.14安装包,https://pa ...

  2. ES6继承语法

    <!--http://www.56.com/u85/v_MTMyNjk1OTc4.html--> <!DOCTYPE html> <html> <head&g ...

  3. 【Tool】Mac环境维护

    1. 安装编译opencv https://blog.csdn.net/lijiang1991/article/details/50756065 /Users/yuhua.cheng/Opt/open ...

  4. IntelliJ IDEA 2017.1.6 x64 的破解

    方式一 现在用这个 http://idea.imsxm.com/好使 步骤如下,点击help按钮,选择Register 点击license server   修改下面的服务器激活地址 方式二 由于Je ...

  5. Top English interview Q&A

    http://www.hjenglish.com/new/p581292/ vocabulary endeavour [ɪn'devər] relevant ['reləvənt] , efficie ...

  6. 2016 年 Java 工具和技术的调查:IDEA 已超过

    最近「技术最前线」看到 RebelLabs 做了一次 2016 年 Java 工具与技术的调查,调查报告虽然是 6 月公布的,但数据一点也不过时. 所以「技术最前线」忙会了一中午,写了这篇文章,带大家 ...

  7. FreeMarker 语法 date 类型处理

    一.java 代码 @Test public void testFreeMarker() throws Exception { //1.创建一个模板文件 //2.创建一个Configuration对象 ...

  8. easyui获取当前点击对象tabs的title和Index

    观察上面打开的tabs选项卡,肯定会有一个目前是被选中状态,而这个状态的class属性也肯定是和其他tabs不一样的,有个class等于tabs-selected的 var title = $('.t ...

  9. Windows下通过FTP自动上传和下载动态文件名

    某个项目中每天会生成一个以文件名+日期.rar文件,如bcpdata2012-08-31.rar文件,动态的部分为日期部分,在windows环境变量中用 %date:~0,10% 表示,这个文件生成后 ...

  10. POJ 2018

    又一水,设dp[i]为以i结尾的有最大平均值的起始位置. #include <iostream> #include <cstdio> #include <cstring& ...