题目

水题,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的更多相关文章

  1. 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 ...

  2. CodeForces #549 Div.2 ELynyrd Skynyrd 倍增算法

    题目 这道题目实际上可以用动态规划来做. 对于每个区间,我们从右边边界,往左边走,如果能走n-1次,那说明以右边边界为起点存在一个题目中说的子链. 利用倍增算法,实际上倍增也是动态规划.f[i][j] ...

  3. CodeForces #549 Div.2 D. The Beatles

    题目 解题思路 关键是要 ,找出L 的组合,然后遍历L的组合,用最大公约数就可以算出来当前L的值要停多少次 怎么找出L的组合呢?饭店是每隔K 有一个,是重复的,我们只需要算出第一个饭店两侧,起点和停顿 ...

  4. [题解] Codeforces Round #549 (Div. 2) B. Nirvana

    Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...

  5. Codeforces Round #549 (Div. 1)

    今天试图用typora写题解 真开心 参考 你会发现有很多都是参考的..zblzbl Codeforces Round #549 (Div. 1) 最近脑子不行啦 需要cf来缓解一下 A. The B ...

  6. [codeforces 549]G. Happy Line

    [codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...

  7. Codeforces #344 Div.2

    Codeforces #344 Div.2 Interview 题目描述:求两个序列的子序列或操作的和的最大值 solution 签到题 时间复杂度:\(O(n^2)\) Print Check 题目 ...

  8. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  9. Codeforces Beta Round #27 (Codeforces format, Div. 2)

    Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...

随机推荐

  1. visual studio code运行时报错,Cannot find module 'webpack'

    前言 今天运行是visual studio code时,报了一个错误Cannot find module 'webpack' ,网上找了很多方法都没解决.下面一起来看看怎么解决 正文 报错: npm ...

  2. Vue生命周期中mounted和created的区别

    参考链接:https://blog.csdn.net/xdnloveme/article/details/78035065

  3. typecho视频播放插件JWPlayer

    JWplayer for typecho是羽中大神开发并持续维护的一款插件,目前插件已经发布了8个版本,涵盖typecho0.8到1.0,插件基于原生的JWPlayer,可以说非常完美,详细使用方法在 ...

  4. 【原创】Linux基础之sudo

    sudo允许用户以其他用户的身份(比如root)执行命令,比如切换用户.执行命令.读写文件等: 配置 sudo配置在:/etc/sudoers ## Sudoers allows particular ...

  5. setInterval动态时间处理

  6. Web Application Vulnerablities

    1. File inclusion berfoe start this caption  i make a conclusion for install third-part as follow I ...

  7. 微信小程序支付开发之申请退款

    微信小程序支付跟微信公众号支付类似,这里不另做记录,如果没有开发过支付,可以查看我关于微信支付的文章 重点记录微信小程序申请退款开发过程中遇到一些坑. 退款接口比支付接口接口多了一个 双向证书 证书介 ...

  8. Python-uiautomator使用说明文档

    https://github.com/xiaocong/uiautomator 这个Python库是基于Android自带的uiautomator测试框架的一个python封包.适用于Android ...

  9. CodeForces 553E Kyoya and Train 动态规划 多项式 FFT 分治

    原文链接http://www.cnblogs.com/zhouzhendong/p/8847145.html 题目传送门 - CodeForces 553E 题意 一个有$n$个节点$m$条边的有向图 ...

  10. 多线程下载图片,同步下载http://www.importnew.com/15731.html

    package mutiDownload; import java.io.IOException; import java.io.InputStream; import java.io.RandomA ...