CodeForces #549 Div.2 C Queen
水题,dfs
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define MAX 100000
struct Node
{
int value;
int c;
int next;
}edge[MAX+5];
int pos;
int head[MAX+5];
int a[MAX+5];
int aa=0;
int n;
void Init()
{
for(int i=1;i<=n;i++)
head[i]=-1;
pos=0;
}
void add(int x,int y,int c)
{
edge[pos].value =y;
edge[pos].c = c;
edge[pos].next = head[x];
head[x]=pos++;
}
void dfs(int root,int c)
{
int x=head[root];
int t=0;
while(x!=-1)
{
if(!(c==1&&edge[x].c==1))
{
t=1;
}
dfs(edge[x].value,edge[x].c);
x=edge[x].next;
}
if(t==0&&c==1)
a[aa++]=root;
}
int main()
{
scanf("%d",&n);
Init();
int p,c;
int root=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&p,&c);
if(p==-1)
{
root=i;
continue;
}
add(p,i,c);
}
dfs(root,0);
if(aa==0)
printf("-1\n");
else
{
sort(a,a+aa);
for(int i=0;i<aa;i++)
{
if(i!=aa-1)
printf("%d ",a[i]);
else
printf("%d\n",a[i]);
}
}
return 0;
}
CodeForces #549 Div.2 C Queen的更多相关文章
- Codeforces Round #549 (Div. 2)C. Queen
C. Queen time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- CodeForces #549 Div.2 ELynyrd Skynyrd 倍增算法
题目 这道题目实际上可以用动态规划来做. 对于每个区间,我们从右边边界,往左边走,如果能走n-1次,那说明以右边边界为起点存在一个题目中说的子链. 利用倍增算法,实际上倍增也是动态规划.f[i][j] ...
- CodeForces #549 Div.2 D. The Beatles
题目 解题思路 关键是要 ,找出L 的组合,然后遍历L的组合,用最大公约数就可以算出来当前L的值要停多少次 怎么找出L的组合呢?饭店是每隔K 有一个,是重复的,我们只需要算出第一个饭店两侧,起点和停顿 ...
- [题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...
- Codeforces Round #549 (Div. 1)
今天试图用typora写题解 真开心 参考 你会发现有很多都是参考的..zblzbl Codeforces Round #549 (Div. 1) 最近脑子不行啦 需要cf来缓解一下 A. The B ...
- [codeforces 549]G. Happy Line
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...
- Codeforces #344 Div.2
Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
随机推荐
- Educational Codeforces Round 52 (Rated for Div. 2)
题目链接 A. Vasya and Chocolate 题意 已知钱,价格,赠送规则求最多获得巧克力数 思路常规算即可 代码 #include <bits/stdc++.h> #defin ...
- 转:spring boot log4j2配置(使用log4j2.yml文件)---YAML 语言教程
转:spring boot log4j2配置(使用log4j2.yml文件) - CSDN博客http://blog.csdn.net/ClementAD/article/details/514988 ...
- JSP标签和JSTL
Java的5个标签库:核心(c).格式化(fmt).函数(fn).SQL(sql).XML(x) SQL.XML库不推荐使用 核心标签库(c) //taglib指令 <%@ taglib pre ...
- 关于 min_25 筛的入门以及复杂度证明
min_25 筛是由 min_25 大佬使用后普遍推广的一种新型算法,这个算法能在 \(O({n^{3\over 4}\over log~ n})\) 的复杂度内解决所有的积性函数前缀和求解问题(个人 ...
- liblensfun 在 mingw 上编译时遇到的奇怪问题
ffmpeg 2018.07.15 增加 lensfun 滤镜; 这个滤镜需要 liblensfun 库; Website: http://lensfun.sourceforge.net/ Sourc ...
- zabbix3.2使用fping批量监控ip的连通性
.在zabbix-agent端安装fping wget http://www.fping.org/dist/fping-3.16.tar.gz tar zxvf fping-3.16.tar.gz c ...
- python学习第22天
封装 properpty classmathod staticmathod
- bootstrap 解决弹出窗口(modal) 常见问题
无法使用键盘esc关闭窗口方法: 首先在modal容器的div中增加属性tabindex="-1",其次设置键盘ESC属性keyboard为true: 方法1:使用js打开窗口时 ...
- 【原创】大叔经验分享(8)创建hive表时用内部表还是外部表
内部表和外部表最主要的一个差别就是删除表或者删除分区时,底层的文件是否自动删除,内部表会自动删除,外部表不会自动删除,所以基础数据表一定要用外部表,即使误删表或分区之后,还可以很容易的恢复回来. 虽然 ...
- 【sklearn】数据预处理 sklearn.preprocessing
数据预处理 标准化 (Standardization) 规范化(Normalization) 二值化 分类特征编码 推定缺失数据 生成多项式特征 定制转换器 1. 标准化Standardization ...