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版的拓扑排序直接套用即 ...
随机推荐
- 源码安装apache
目标:源码安装apache 依赖包:apr.apr-util和pcre.其中pcre正则库要先安装,apr和apr-util(已解压)可以复制到apache下的资源库srclib下. 安装pcre: ...
- office 2016 专业增强版 和 visio 2016 专业版 下载安装(附带激活工
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://babyshen.blog.51cto.com/8405584/1697910 o ...
- ASP+Access UTF-8 网页乱码问题解决办法
用ACCESS数据库和ASP做网站时用UTF-8编码有时会出现乱码,再者网页出错或者刷新页面后就是乱码,如果数据库取值乱码在开头加上<%@LANGUAGE="VBSCRIPT" ...
- Xcode运行的错误bug收集
libopencore-amrnb.a(wrapper.o)' does not contain bitcode. You must rebuild it with bitcode enabled ( ...
- C#:序列化值与解码二进制
1.将对象序列化为二进制值,供WebBrowser传值: private static byte[] PostDataToBytes(Data postData) { JavaScriptSerial ...
- java中的内存一般分成几部分?
java中的内存被分成以下四部分: ①.代码区 ②.栈区 ③.堆区 ④.静态区域 栈区:由编译器自动分配释放,存放函数的参数值.局部变量的值等:具体方法执行结束后,系统自动释放JVM内存资源 ...
- java环境log4j日志环境的配置。
首先需要4个jar包.下载地址如下 http://pan.baidu.com/s/1i4k3fiH 期中包含如下包,放到工程的lib中即可. 除此之外还需要一个配置文件,分享链接如下. htt ...
- java单元测试(Junit)
Eclipse最基本的模块测试 1:首先创建一个java工程,在工程中创建一个被单元测试的Student数据类,如下: package UnitTest; public class Student { ...
- linux下查看电脑配置
1. 查看cpu ~$ cat /proc/cpuinfo 2. 查看内存占用 ~$ cat /proc/meminfo 3. 硬盘分区 $ cat /proc/partitions 4. ubunt ...
- WebForm跨页面传值---内置对象
一.Response Response - 响应请求对象 string path = "Default2.aspx": (1)Response.Redirect(path); -- ...