博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5154 Harry and Magical Computer bfs
阅读量:6976 次
发布时间:2019-06-27

本文共 1895 字,大约阅读时间需要 6 分钟。

Harry and Magical Computer

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 499    Accepted Submission(s): 233

Problem Description
In reward of being yearly outstanding magic student, Harry gets a magical computer. When the computer begins to deal with a process, it will work until the ending of the processes. One day the computer got n processes to deal with. We number the processes from 1 to n. However there are some dependencies between some processes. When there exists a dependencies (a, b), it means process b must be finished before process a. By knowing all the m dependencies, Harry wants to know if the computer can finish all the n processes.
 

 

Input
There are several test cases, you should process to the end of file.
For each test case, there are two numbers n m on the first line, indicates the number processes and the number of dependencies.
1n100,1m10000
The next following m lines, each line contains two numbers a b, indicates a dependencies (a, b). 1a,bn
 

 

Output
Output one line for each test case.
If the computer can finish all the process print "YES" (Without quotes).
Else print "NO" (Without quotes).
 

 

Sample Input
3 2 3 1 2 1 3 3 3 2 2 1 1 3
 

 

Sample Output
YES NO

 

 

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 100001const int inf=0x7fffffff; //无限大 int map[101][101];int vis[101];int flag[101];int main(){ int n,m; while(cin>>n>>m) { memset(map,0,sizeof(map)); memset(vis,0,sizeof(vis)); memset(flag,0,sizeof(flag)); int a,b; for(int i=0;i
>a>>b; map[b-1][a-1]=1; flag[a-1]=1; } queue
q; for(int i=0;i

 

转载地址:http://bcesl.baihongyu.com/

你可能感兴趣的文章
PHP学习:$_GET,$_POST,$_REQUEST和$_SERVER的一些用法,以及parse_str方法
查看>>
java下DES加密与解密
查看>>
Nagios使用SendEmail发送邮件
查看>>
Domino8.5.1和Exchange2010共用一个邮件域实现邮件收发
查看>>
截图留存
查看>>
linux PDF转换为SWF
查看>>
ASP.net 中的AJAX学习记录之四 updateProgress控件的简单用法
查看>>
怎样自动生成makefile
查看>>
Windows2008R2 AD降级错误解决方案
查看>>
datagridview的数据库设计与使用
查看>>
资源管理器的学习笔记一
查看>>
JAVA中写时复制(Copy-On-Write)Map实现
查看>>
推荐12个漂亮的 CSS3 按钮实现方案
查看>>
顺序栈
查看>>
[译] OpenStack Kilo 版本中 Neutron 的新变化
查看>>
Lintcode: Sqrt(X)
查看>>
iOS:UIPageViewController翻页控制器控件详细介绍
查看>>
网站推广优化教程100条(SEO,网站关键字优化,怎么优化网站,如何优化网站关键字)...
查看>>
SQLServer游标(Cursor)简介和使用说明
查看>>
iOS: ios视频播放(MPMediaPlayerController,AVPlayer,AVPlayerViewcontroller、ffmpeg-AVPlayer)...
查看>>