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版的拓扑排序直接套用即 ...
随机推荐
- linux设备驱动归纳总结(七):1.时间管理与内核延时【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-100005.html linux设备驱动归纳总结(七):1.时间管理与内核延时 xxxxxxxxxxx ...
- 161208、Java enum 枚举还可以这么用
在大部分编程语言中,枚举类型都会是一种常用而又必不可少的数据类型,Java中当然也不会例外.然而,Java中的Enum枚举类型却有着许多你意想不到的用法,下面让我们一起来看看. 先来看一段代码示例: ...
- js 如何生成唯一且不可预测的 ID
通常数据库可以生成唯一的 ID,最多的就是数字序列,也有像 MongoDB 这样产生组合序列的,不过这种形式的 ID 由于是序列,是可以预测的.如果想得到不可预测且唯一的 ID,方法还是有的. 下面主 ...
- oracle查看表占磁盘大小
select segment_name, bytes/1024/1024 from user_segments S where S.segment_type = 'TABLE' AND S.segme ...
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
Polygon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 中国地图 xaml Canvas
<Canvas x:Name="LayoutRoot" Height="560" Width="700" Background=&q ...
- Adam 演示demo内容整理
在这个6个多G的演示demo中,还是发现了不少东西. 这篇文章八卦向的东西比较多,不过支持abc格式的话,做Cutscene一下子多了很多可以用的东西. 1.在插件目录下发现了ABC格式的导入dll. ...
- Java中的类加载器
转载:http://blog.csdn.net/zhangjg_blog/article/details/16102131 从java的动态性到类加载机制 我们知道,Java是一种动态语言.那么怎 ...
- SharePoint自动化系列——创建MMS terms
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...
- [转]get,post数据长度的限制
一.问题起因 在某项目释放后Bug统计的附件<释放后问题>里有: 问题 原因 分析 备注 CSV处理时,如果处理的主题数过多,发生URL参数上限的错误: 可变长度的参数通过URL方式传递, ...