hdu 5154 Harry and Magical Computer 拓扑排序
Harry and Magical Computer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
For each test case, there are two numbers n m on the first line, indicates the number processes and the number of dependencies. 1≤n≤100,1≤m≤10000
The next following m lines, each line contains two numbers a b, indicates a dependencies (a, b). 1≤a,b≤n
If the computer can finish all the process print "YES" (Without quotes).
Else print "NO" (Without quotes).
3 1
2 1
3 3
3 2
2 1
1 3
NO
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=2e3+,M=1e6+,inf=1e9;
int n,m;
vector<int>edge[N];
int du[N];
int main()
{
while(~scanf("%d%d",&n,&m))
{
queue<int>q;
memset(du,,sizeof(du));
for(int i=;i<=n;i++)
edge[i].clear();
int ans=;
for(int i=;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
edge[u].push_back(v);
du[v]++;
}
for(int i=;i<=n;i++)
{
if(!du[i])q.push(i);
}
while(!q.empty())
{
int v=q.front();
q.pop();
ans++;
for(int i=;i<edge[v].size();i++)
{
du[edge[v][i]]--;
if(!du[edge[v][i]])
q.push(edge[v][i]);
}
}
if(ans==n)
printf("YES\n");
else
printf("NO\n");
}
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 ...
- BC Harry and Magical Computer (拓扑排序)
Harry and Magical Computer Accepts: 350 Submissions: 1348 Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5154 Harry and Magical Computer 有向图判环
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5154 题解: 有向图判环. 1.用dfs,正在访问的节点标记为-1,已经访问过的节点标记为1,没有访 ...
- (简单) HDU 5154 Harry and Magical Computer,图论。
Description In reward of being yearly outstanding magic student, Harry gets a magical computer. When ...
- HDU 5154 Harry and Magical Computer bfs
Harry and Magical Computer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 【HDOJ】5154 Harry and Magical Computer
拓扑排序. /* 5154 */ #include <iostream> #include <cstdio> #include <cstring> #include ...
- HDU 6073 Matching In Multiplication(拓扑排序+思维)
http://acm.hdu.edu.cn/showproblem.php?pid=6073 题意:有个二分图,左边和右边的顶点数相同,左边的顶点每个顶点度数为2.现在有个屌丝理解错了最佳完美匹配,它 ...
- HDU 5195 DZY Loves Topological Sorting 拓扑排序
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5195 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- HDU 3342 Legal or Not(拓扑排序判断成环)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3342 题目大意:n个点,m条有向边,让你判断是否有环. 解题思路:裸题,用dfs版的拓扑排序直接套用即 ...
随机推荐
- V4L2应用程序框架-二【转】
本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11371439 V4L2驱动框架 主设备号: 81 次设备号: 0-63 64 ...
- IIS7.5真变态,服务器时间格式导致不生成WebResource.axd
把时间调成HH:mm格式后,IIS不生成WebResource.axd了,,,从凌晨一点弄到现在......
- Android关机闹钟实现
Android关机闹钟实现 时间转换网站:http://tool.chinaz.com/Tools/unixtime.aspx 1.apk层 这个还是比较简单的,百度一下就可以看到apk的代码,我之前 ...
- 【转】Tomcat调优指南
转载地址:http://blog.csdn.net/woohooli/article/details/3954792 1 概述 本文档主要介绍了Tomcat的性能调优的原理和方法.可 ...
- Unity GUI内绘制贝塞尔曲线
用Handles可以直接在GUI下绘制贝塞尔 using UnityEditor; using UnityEngine; using System.Collections; public class ...
- Poj(2195),最小费用流,SPFA
题目链接:http://poj.org/problem?id=2195 Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- malloc与kmalloc
在设备驱动程序中动态开辟内存,不是用malloc,而是kmalloc,或者用get_free_pages直接申请页.释放内存用的是kfree,或free_pages. 对于提供了MMU(存储管理器,辅 ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- jquery easyui中文培训文档
目 录 1.... Accordion(可折叠标签)... 2 1.1 实例... 2 1.2 参数... 3 2.... DateBox(日期框)... 4 2 ...
- 2016年11月23日 星期三 --出埃及记 Exodus 20:14
2016年11月23日 星期三 --出埃及记 Exodus 20:14 "You shall not commit adultery.不可奸淫.