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< ...
随机推荐
- jQuery UI弹出新窗体
借助jqueryUI 的Dialog 在隐藏的div中嵌入Iframe 改变iframe的路径 如果项目经常用到弹出新窗体,则利用模板,把此代码和html 放入父页面中,实现父级调用, <in ...
- Codeforces 1101G(线性基)
题目链接 题意 将序列尽可能分成多段使得任意$x \geq 1$段内的所有元素的异或和大于$0$问最多多少段 思路 首先,如果所有元素异或和等于$0$答案显然为$-1$,否则构造整个序列的线性基,这个 ...
- mui上拉刷新+下拉加载
具体操作见代码: <!doctype html> <html> <head> <meta charset="UTF-8"> < ...
- codeblocks修改字体颜色-背景颜色
常用: 1. 编辑器背景-豆沙绿配置:色调85,饱和度123,亮度205: 2. 注释颜色-紫色:rgb(255,0,255): 参考: 改变codeblocks里面各种注释的颜色 常用颜色的RGB值 ...
- Python基础【第一篇】
一.Python简介 Python的创始人(Guido von Rossum 荷兰人),Guido希望有一种语言既能像C一样方便地调用操作系统的功能接口,也能像shell脚本一样,轻松地实现编程,A ...
- 【Java】JDK/JVM相关工具
1.JDK自带工具 1)常见的用法参见:https://cloud.tencent.com/developer/article/1379487 2)HSDB,即Hotspot debugger,位置在 ...
- 02-Django基础知识
一.内容回顾 1.web应用程序 2.HTTP协议 a.http协议特性 b.http请求格式 c.http响应格式 3.wsgiref模块 4.Django下载与简单应用 a.Django简介(MT ...
- VC调用静态库、动态库
静态库 // 相对路径 或者 绝对路径 #include "yourlib.h" //相对路径 或者 绝对路径 #pragma comment(lib, "yourlib ...
- python 基于机器学习识别验证码
1.背景 验证码自动识别在模拟登陆上使用的较为广泛,一直有耳闻好多人在使用机器学习来识别验证码,最近因为刚好接触这方面的知识,所以特定研究了一番.发现网上已有很多基于machine learni ...
- (三)Knockout 控制流程
foreach 示例1:迭代数组 foreach binding主要作用于lists或是tables内数据单元的动态绑定.下面是一个简单的例子: <table> <thead> ...