1242. Werewolf(dfs)
简单dfs 往孩子方向搜一遍 父母方向搜一遍 输入还搞什么字符串。。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;
vector<int>fa[];
vector<int>ch[];
int u,v,q[];
int w[],vis1[],vis2[],o;
void dfs1(int u)
{
int i;
for(i = ; i < (int)fa[u].size() ; i++)
{
int v = fa[u][i];
if(!vis1[v])
{
vis1[v] = ;
dfs1(v);
}
}
}
void dfs2(int u)
{
int i;
for(i = ; i < (int)ch[u].size() ; i++)
{
int v = ch[u][i];
if(!vis2[v])
{
vis2[v] = ;
dfs2(v);
}
}
}
int main()
{
int i,j,n;
char s1[],s2[];
scanf("%d",&n);
while(cin>>s1)
{
if(strcmp(s1,"BLOOD")==)
break;
cin>>s2;
u = atoi(s1);
v = atoi(s2);
fa[u].push_back(v);
ch[v].push_back(u);
}
int g = ;
while(scanf("%d",&j)!=EOF)
{
g++;
q[g] = j;
}
for(i = ; i <= g ; i++)
{
if(!vis1[q[i]])
{
vis1[q[i]] = ;
dfs1(q[i]);
}
}
for(i = ; i <= g ; i++)
{
if(!vis2[q[i]])
{
vis2[q[i]] = ;
dfs2(q[i]);
}
}
for(i = ; i <= n ;i++)
if(!vis2[i]&&!vis1[i])
{
o++;
w[o] = i;
}
if(!o)
printf("0\n");
else
{
for(i = ; i < o ; i++)
printf("%d ",w[i]);
printf("%d\n",w[o]);
}
return ;
}
1242. Werewolf(dfs)的更多相关文章
- URAL 1242 Werewolf(DFS)
Werewolf Time limit: 1.0 secondMemory limit: 64 MB Knife. Moonlit night. Rotten stump with a short b ...
- 1208. Legendary Teams Contest(dfs)
1208 简单dfs 对于每个数 两种情况 取还是不取 #include <iostream> #include<cstdio> #include<cstring> ...
- hdu 1242 Rescue(bfs)
此刻再看优先队列,不像刚接触时的那般迷茫!这也许就是集训的成果吧! 加油!!!优先队列必须要搞定的! 这道题意很简单!自己定义优先级别! +++++++++++++++++++++++++++++++ ...
- HDU 1242 Rescue(优先队列)
题目来源: http://acm.hdu.edu.cn/showproblem.php?pid=1242 题目描述: Problem Description Angel was caught by ...
- 1137. Bus Routes(dfs)
1137 做过一样的 怎么又忘了 再一次搜超时 不用回溯 #include <iostream> #include<cstdio> #include<cstring> ...
- 1124. Mosaic(dfs)
1124 需要想那么一点点吧 一个连通块中肯定不需要伸进手不拿的情况 不是一个肯定会需要这种情况 然后注意一点 sum=0的时候 就输出0就可以了 不要再减一了 #include <iostre ...
- 1742. Team building(dfs)
1742 最小的是找联通块数 最大的找环 一个环算一个 其它的数各算一个 #include <iostream> #include<cstdio> #include<cs ...
- HDU 1242——Rescue(优先队列)
题意: 一个天使a被关在迷宫里,她的很多小伙伴r打算去救她.求小伙伴就到她须要的最小时间.在迷宫里有守卫.打败守卫须要一个单位时间.假设碰到守卫必须要杀死他 思路: 天使仅仅有一个,她的小伙伴有非常多 ...
- PAT(A) 1148 Werewolf - Simple Version(Java)逻辑推理
题目链接:1148 Werewolf - Simple Version (20 point(s)) Description Werewolf(狼人杀) is a game in which the p ...
随机推荐
- UML 小结(2)- 理论理解
什么是UML: UML是统一建模语言(UML是 Unified Modeling Language的缩写)是用来对软件密集系统进行可视化建模的一种语言. UML为面向对象开发系统的产品进行说明.可视化 ...
- 微软职位内部推荐-Enterprise Architect - BDE - BJ
微软近期Open的职位: Enterprise ArchitectCloud, HTML5, Big Data and Mobile are technology trends driving pro ...
- Careercup - Google面试题 - 4807591515389952
2014-05-06 00:45 题目链接 原题: What would happen if you have only one server for a web cache (a web brows ...
- mysql存储过程中字符串参数单引号
注意:存储过程中单引号 ,四个单引号 SET @sql = CONCAT('select user_id into ',m_user_id,' from go_user where mobile = ...
- Android PopupWindow 点击消失解决办法
1.点击PopupWindow 外部区域时,PopupWindow消失 popMenu = new PopupWindow(getApplicationContext()); popMenu.setW ...
- ubuntu 安装git
问题描述: ubuntu安装git 问题解决: (1)ubuntu下载git 注: 使用命令apt-get install git安装 (2)查看g ...
- 使用node的http模块实现爬虫功能,并把爬到的数据存入mongondb
刚开始使用http中间件做爬虫其实蛮多坑的,最主要的坑就是编码问题,有很多中文网站的采用的gb2313的编码方式,这个在爬到的报文解析就很蛋碎, 因为http中间件对utf-8支持的比较好,所以针对这 ...
- [设计模式] 15 解释器模式 Interpreter
在GOF的<设计模式:可复用面向对象软件的基础>一书中对解释器模式是这样说的:给定一个语言,定义它的文法的一种表示,并定义一个解释器,这个解释器使用该表示来解释语言中的句子.如果一种特定类 ...
- JAVA数据源连接方式汇总
最近在研究JAVA的数据源连接方式,学习的时候发现了一位同行写的文章,转载过来,留作记录! 一.问题引入 在java程序中,需要访问数据库,做增删改查等相关操作.如何访问数据库,做数据库的相关操作呢? ...
- SVN库实时同步设置
为了安全起见,SVN服务器除了做定时全量备份和增量备份以外,如条件允许,可做实时备份. 这需要2台机器,一台是master server,另一台做mirror server.master做主服务,mi ...