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 ...
随机推荐
- Ubuntu 16.04 安装 Django==1.11.8
vim InStall-Django.sh #!/bin/bash rm -rf /usr/bin/python ln -s /usr/bin/python3 /usr/bin/python mkd ...
- JS 输名字随机弹出
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- mysql备份脚本二(带日志)
#!/bin/bashdb_PATH='/shareSAN/mysqldata/ocs/mysql_back_wjf' #备份文件保存的路径#db_DBNAME='sz_ocs' #备份的数据库名db ...
- 树状数组||归并排序求逆序对+离散化 nlogn
我好咸鱼. 归并排序之前写过,树状数组就是维护从后往前插入,找比现在插入的数大的数的数量. 如果值域大,可以离散化 #include <cstdio> #include <cstri ...
- Python 不同列表时间测试
import timeit import threading def test1(): l = [] for i in range(1000): l = l + [i] def test2(): l ...
- GOF23设计模式之建造者模式
GOF23设计模式之建造者模式 场景: 我们要建造一个复杂的产品.比如:神州飞船,Iphone.这个复杂的产品的创建.有这样的一个问题需要处理: 装配这些子组件是不是有个步骤问题? 实际开发中,我们所 ...
- 手机QQ架构的浅谈
手机QQ的原本的产品定位定位于移动社交,并将娱乐与生活服务相结合,整体的架构模块QQ主要分为登录注册,消息,聊天,联系人,动态,侧边栏,设置等几大模块.其中消息模块和聊天模块是核心模块.好友动态及联系 ...
- H3C防火墙——回环流量问题(内网终端通过外网IP访问内部服务器)
http://www.bubuko.com/infodetail-1533703.html
- 洛谷—— P1803 凌乱的yyy
https://www.luogu.org/problem/show?pid=1803 题目背景 快noip了,yyy很紧张! 题目描述 现在各大oj上有n个比赛,每个比赛的开始.结束的时间点是知道的 ...
- Eclipse设置jdk相关
2.window->preferences->java->Compiler->设置右侧的Compiler compliance level 3.window->prefe ...