Codeforces Round #468 (Div. 2 )D. Peculiar apple-tree_BFS
题目简单,不多解释。
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的更多相关文章
- 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 ...
- Codeforces Round #468 Div. 2题解
A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 ...
- Codeforces Round #468 Div. 1
D:首先考虑如果给定白棋位置,如何判断胜负.黑棋获胜需要四个方向都有能贴上白棋的棋子.由于每一轮都必须移动,显然先对平面黑白染色一下,只有与白棋所在格异色的黑棋才需要考虑.考虑让一个黑棋去贴上白棋某个 ...
- 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 ...
- codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)
题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率. 用map记录每个字母出现的位置.对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- sublim Text3 配置python3环境
一.安装Sublime Text 3 1.双击下载的.exe文件安装,安装路径不要有中文目录 2.安装Sublime Text 3时,勾选“Add to explorer context menu”, ...
- MySQL笔记5-----索引(覆盖索引等)
1.概念: 覆盖索引:(个人理解)就是包含所有查询记录的索引.当查询量过大时可以采用覆盖索引来进行查询,效率较高. 回表:建立覆盖索引就是避免回表,回表效率会很慢. select查询的字段只有索引列, ...
- ios高效开发二--ARC跟block那点事
block是可以捕捉上下文的特殊代码块. block可以访问定义在block外的变量,当在block中使用时,它就会为其在作用域内的每个标量变量创建一个副本. 如果通过self拥有一个block,然后 ...
- call和apply的使用
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- ES6继承语法
<!--http://www.56.com/u85/v_MTMyNjk1OTc4.html--> <!DOCTYPE html> <html> <head&g ...
- CentOS 笔记(四) Jexus部署相关
①设置jexus 为服务 cd /lib/systemd/system/ sudo vi jexus.service #注意 jexus 实际路径 [Unit] Description=jexus A ...
- parted分区流程操作
parted不同于fdisk(<2T)它比fdiskf更加灵活,fdisk需保持后才能生效,而parted是分区后直接生效! 磁盘分区步骤: 1.parted /dev/sdb #进入磁盘分区 ...
- tomcat 内存溢出问题(OutOfMemoryError: PermGen space)
导入公司项目的时候出现的问题,在此记录处理方法. tomcat在启动的时候报错:OutOfMemoryError: PermGen space PermGen space的全称是Permanent G ...
- HDU 1042 N!【大数】
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...
- HDOJ 3339 In Action
最短路+01背包 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...