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 ...
随机推荐
- JS 封装一个求n~m的求和函数
var a = 0; cc(2,10); function cc(n,m){ for(var i =n;i<(m+1);i++){ a = a + ...
- WEBGL学习【十】运动模型
<!DOCTYPE HTML> <html lang="en"> <head> <title>LWEBGL6.2, Animated ...
- php 流
php:// — 访问各个输入/输出流(I/O streams) 说明 PHP 提供了一些杂项输入/输出(IO)流,允许访问 PHP 的输入输出流.标准输入输出和错误描述符, 内存中.磁盘备份的临时文 ...
- P1421 小玉买文具
... 题目描述 班主任给小玉一个任务,到文具店里买尽量多的签字笔.已知一只签字笔的价格是1元9角,而班主任给小玉的钱是a元b角,小玉想知道,她最多能买多少只签字笔呢. 输入输出格式 输入格式: 输入 ...
- PuTTY_0.67.0.0工具链接linux
1.虚拟机设置 在网络适配器中选中桥接模式,勾选复制物理网络链接状态(p)选项.点击确认. 2.开启虚拟机,检查是否安装有ssh服务器 a.查看是否启动ssh服务器 ps -a | grep ssh ...
- Linux 文件压缩
压缩工具 compress/uncompress:对应 .Z 结尾的压缩格式文件 压缩格式:gz.bz2.xz.zip.Z gzip 压缩文件并删除源文件(生成.gz的文件) gunzip 解 ...
- 编译htop
git clone https://github.com/hishamhm/htop cd htop ./autogen.sh ./configure make make install
- Context - React跨组件访问数据的利器
Context提供了一种跨组件访问数据的方法.它无需在组件树间逐层传递属性,也可以方便的访问其他组件的数据 在经典的React应用中,数据是父组件通过props向子组件传递的.但是在某些特定场合,有些 ...
- [LeetCode] 75. 颜色分类(荷兰国旗)
class Solution { public: void sortColors(vector<int>& nums) { ,current=,end=nums.size()-; ...
- Ubuntu下安装Tensorflow
本文目录 引言 基于Anaconda的tensorflow安装 1 下载linux版本的Anaconda安装包 2 安装Anaconda 利用anaconda安装tensorflow 1 建立一个 c ...