ural 1242. Werewolf
1242. Werewolf
Memory limit: 64 MB
Input
Output
Samples
input | output |
---|---|
8 |
4 5 7 |
6 |
0 |
Problem Source: Ural State University Personal Programming Contest, March 1, 2003
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline bool Getint(int &Ret)
{
Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == 'B') Flag = ;
if(Flag == && Ch == 'D') break;
Ch = getchar();
}
if(Flag) return ;
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return ;
} const int N = ;
int n;
vector<int> Parent[N], Child[N], Ans;
bool Visit[N]; inline void Input()
{
scanf("%d", &n);
int x, y;
while(Getint(x))
{
Getint(y);
Parent[x].pub(y), Child[y].pub(x);
}
} inline void GoUp(int x)
{
Visit[x] = ;
int Length = sz(Parent[x]);
Rep(i, Length) GoUp(Parent[x][i]);
Parent[x].clear();
} inline void GoDown(int x)
{
Visit[x] = ;
int Length = sz(Child[x]);
Rep(i, Length) GoDown(Child[x][i]);
Child[x].clear();
} inline void Solve()
{
int x;
while(~scanf("%d", &x))
{
GoUp(x);
GoDown(x);
} For(i, , n)
if(!Visit[i]) Ans.pub(i);
if(sz(Ans))
{
Rep(i, sz(Ans)-) printf("%d ", Ans[i]);
printf("%d\n", Ans.back());
}
else puts("");
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("A");
#endif
Input();
Solve();
return ;
}
ural 1242. Werewolf的更多相关文章
- URAL 1242 Werewolf(DFS)
Werewolf Time limit: 1.0 secondMemory limit: 64 MB Knife. Moonlit night. Rotten stump with a short b ...
- 1242. Werewolf(dfs)
1242 简单dfs 往孩子方向搜一遍 父母方向搜一遍 输入还搞什么字符串.. #include <iostream> #include<cstdio> #include< ...
- WereWolf项目 Postmortem
WereWolf项目 Postmortem (博客园的MarkDown编辑器好像有些问题,编号都显示1..) 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描 ...
- Werewolf流程分析
werewolf大致流程 首先是房主创建房间,创建成功以后房主开启web socket连接. 其他成员加入房间,加入房间后新成员和老成员的游戏玩家列表都会更新,然后新成员也要开启web socket连 ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
随机推荐
- 2d背景循环
using UnityEngine; using System.Collections; /// <summary> /// 2d背景循环滚动 /// </summary> p ...
- POJ 矩阵相乘 (随机化算法-舍伍德(Sherwood))
周三的算法课,主要讲了随机化算法,介绍了拉斯维加斯算法,简单的理解了为什么要用随机化算法,随机化算法有什么好处. 在处理8皇后问题的时候,穷举法是最费时的,回朔比穷举好点,而当数据量比较大的时候,如1 ...
- SSDB 数据库如何换用 rocksdb 引擎?
牧童遥指杏花村,一枝红杏出墙来… SSDB 数据库如何换用 rocksdb 引擎? idea's blog 2014-04-12 71 阅读 rocksdb NoSQL SSDB 数据库使用的是 G ...
- Xenomai 安装准备工作
一些安装xenomai的参考资料: http://my.oschina.net/hevakelcj/blog/124290 http://blog.sina.com.cn/s/blog_60b9ee1 ...
- Android measure和layout的一点理解
首先,推荐文章,http://blog.csdn.net/hqdoremi/article/details/9980481,http://www.docin.com/p-571954086.html ...
- ARGB32 to YUV12 利用 SDL1.2 SDL_ttf 在视频表面输出文本
提示:ARGB alpha通道的A + 原YUV表面的y0 + 要写进去的y1 = 计算出新的y2. 计算公式为 ( y1 * a + y0 * ( 255 - a ) ) / 255 void rg ...
- Java for LeetCode 076 Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters ...
- POJ 3977
Subset Time Limit: 30000MS Memory Limit: 65536K Total Submissions: 1373 Accepted: 228 Descriptio ...
- Cocos2d-JS的屏幕适配方案
Cocos2d引擎为游戏开发者提供了屏幕适配策略(Resolution Policy)解决方案. 使用方式 1. 设置屏幕适配策略(Resolution Policy) 如果你还没有用过Resolut ...
- unix/linux进程详解——代码
#include <iostream>#include <vector>#include <cstdint>#include <cstring>#inc ...