(简单) HDU 5154 Harry and Magical Computer,图论。
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; bool vis[];
bool rem[];
int n,m;
int first[];
int next[];
int bs[],be[]; bool dfs(int x)
{
int t=first[x]; while(t)
{
if(rem[be[t]]) //这里要注意先判断。
return ; if(vis[be[t]]==)
{
vis[be[t]]=;
rem[be[t]]=; if(dfs(be[t])==)
return ;
rem[be[t]]=;
} t=next[t]; //不然会无限循环。
} return ;
} bool getans()
{
for(int i=;i<=n;++i)
if(vis[i]==)
{
memset(rem,,sizeof(rem)); //这里要注意清零。
rem[i]=;
vis[i]=;
if(dfs(i)==)
return ;
} return ;
} int main()
{
int a,b;
int temp; while(~scanf("%d %d",&n,&m))
{
memset(vis,,sizeof(vis));
memset(first,,sizeof(first));
memset(next,,sizeof(next)); for(int i=;i<=m;++i)
{
scanf("%d %d",&a,&b);
bs[i]=b;
be[i]=a;
temp=first[b];
first[b]=i;
next[i]=temp;
} if(getans())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
} return ;
}
(简单) HDU 5154 Harry and Magical Computer,图论。的更多相关文章
- hdu 5154 Harry and Magical Computer
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5154 Harry and Magical Computer Description In reward ...
- hdu 5154 Harry and Magical Computer 拓扑排序
Harry and Magical Computer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 5154 Harry and Magical Computer bfs
Harry and Magical Computer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 5154 Harry and Magical Computer 有向图判环
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5154 题解: 有向图判环. 1.用dfs,正在访问的节点标记为-1,已经访问过的节点标记为1,没有访 ...
- 【HDOJ】5154 Harry and Magical Computer
拓扑排序. /* 5154 */ #include <iostream> #include <cstdio> #include <cstring> #include ...
- hdu 5154 拓扑排序
例题:hdu 5154 链接 http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思是第一行先给出n和m表示有n件事,m个关系,接下来输入m行,每行有 ...
- BC Harry and Magical Computer (拓扑排序)
Harry and Magical Computer Accepts: 350 Submissions: 1348 Time Limit: 2000/1000 MS (Java/Others) ...
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...
随机推荐
- iOS label换行 自适应
//自动折行设置 addressDetailLab.lineBreakMode = NSLineBreakByWordWrapping; addressDetailLab.numberOfLines ...
- Git学习 -- 工作区和暂存区
工作区(working directory): 就是能看到的目录,如我的git文件夹 版本库(repository): 工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库 里面最重要的就 ...
- windows 系统注册dll文件
使用管理员身份注册:命令提示符 管理员身份运行 32 位系统:regsvr32 %windir%\system32\jscript.dll 64 位系统:regsvr32 %windir%\SysWO ...
- Friends and Subsequences
Friends and Subsequences Mike and !Mike are old childhood rivals, they are opposite in everything th ...
- 生日蛋糕(DFS)
题意: Description 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕 ...
- Kali渗透测试学习
http://blog.chinaunix.net/uid-26349264-id-4041727.html
- jenkins邮件设置
不要忘记上面的系统管理员的邮箱也要先填好.
- SDAU课程练习--problemC
题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...
- Java中的随机数生成器:Random,ThreadLocalRandom,SecureRandom
Java中的随机数生成器:Random,ThreadLocalRandom,SecureRandom 文中的 Random即:java.util.Random,ThreadLocalRandom 即: ...
- CSS3的background-size
DEMO一.background-size:auto; 我来看第一个DEMO,在前面的DEMO上加上和个class名为"backgroundSizeAuto",在这个Demo上我们 ...