博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL 1242 Werewolf(DFS)
阅读量:6186 次
发布时间:2019-06-21

本文共 2696 字,大约阅读时间需要 8 分钟。

Werewolf

Time limit: 1.0 second
Memory limit: 64 MB
Knife. Moonlit night. Rotten stump with a short black-handled knife in it. Those who know will understand. Disaster in the village. Werewolf.
There are no so many residents in the village. Many of them are each other's relatives. Only this may help to find the werewolf. The werewolf is merciless, but his descendants never become his victims. The werewolf can drown the village in blood, but he never kills his ancestors.
It is known about all the villagers who is the child of whom. Also, the sad list of the werewolf's victims is known. Your program should help to determine the suspects. It would be a hard task, if a very special condition would not hold. Namely, citizens of the village are not used to leave it. If some ancestor of some citizen lives in the village, then also his immediate ancestor does. It means, that, for example, if the father of the mother of some citizen still lives in the village, than also his mother still lives.

Input

The first line contains an integer
N, 1 <
N ≤ 1000, which is the number of the villagers. The villagers are assigned numbers from 1 to
N. Further is the description of the relation "child-parent": a sequence of lines, each of which contains two numbers separated with a space; the first number in each line is the number of a child and the second number is the number of the child's parent. The data is correct: for each of the residents there are no more than two parents, and there are no cycles. The list is followed by the word "BLOOD" written with capital letters in a separate line. After this word there is the list of the werewolf's victims, one number in each line.

Output

The output should contain the numbers of the residents who may be the werewolf. The numbers must be in the ascending order and separated with a space. If there are no suspects, the output should contain the only number 0.

Samples

input output
81 33 64 56 24 68 1BLOOD38
4 5 7
61 23 21 43 42 65 25 4BLOOD25
0
Problem Author: Leonid Volkov
【分析】简单的递归。
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f#define mod 10000typedef long long ll;using namespace std;const int N=1005;const int M=100005;int n,m,k=0,a,b;int vis[N];char str[20];bool flag=false;vector
vec,parent[N],chil[N];void dfs(int u,int f){ //printf("!!!%d %d\n",u,f); vis[u]=1; if(!f){ for(int i=0;i
=9)break; } for(int i=0;i
View Code

 

转载于:https://www.cnblogs.com/jianrenfang/p/5875204.html

你可能感兴趣的文章
Python classmethod(类方法) 和 类属性 静态方法(缺少)
查看>>
我的友情链接
查看>>
vsftpd的基于pam_mysql的虚拟用户配置示例
查看>>
MYSQL数据库迁移到ORACLE数据库
查看>>
C语言中运算符的优先级排序
查看>>
nodejs tutorial - 5 单元测试 2015-3-24
查看>>
ubuntu下未获得锁问题
查看>>
我的友情链接
查看>>
前端面试题整理
查看>>
odoo 10 的 两个模块分析和细微改动
查看>>
Azure上的Web Apps极其相关服务
查看>>
HP iLo licenses
查看>>
IIS7.5中asp.net 区域 area中的路径 URLRewriter报错 .. 在顶级目录上退出
查看>>
javascript的apply和call,执行环境,垃圾回收,闭包
查看>>
Linux下阻塞与非阻塞IO
查看>>
寻找内网主机被***的方法
查看>>
我使用过的Linux命令之mv - 文件或目录改名、移动位置
查看>>
参数处理-Shell传入参数的处理
查看>>
如何查看apk需要支持的Android版本
查看>>
Required request body is missing 错误解决
查看>>