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. 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
 
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 <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
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 100001
const int inf=0x7fffffff; //无限大
int map[][];
int vis[];
int flag[];
int main()
{
int n,m;
while(cin>>n>>m)
{
memset(map,,sizeof(map));
memset(vis,,sizeof(vis));
memset(flag,,sizeof(flag));
int a,b;
for(int i=;i<m;i++)
{
cin>>a>>b;
map[b-][a-]=;
flag[a-]=;
}
queue<int> q;
for(int i=;i<n;i++)
{
if(flag[i]==)
{
q.push(i);
vis[i]=;
}
}
int now;
int next;
while(!q.empty())
{
now=q.front();
for(int i=;i<n;i++)
{
if(map[now][i]==)
{
if(vis[i]==)
continue;
q.push(i);
vis[i]=;
}
}
q.pop();
}
int flag1=;
for(int i=;i<n;i++)
{
if(vis[i]==)
{
flag1=;
break;
}
}
if(flag1==)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}

HDU 5154 Harry and Magical Computer bfs的更多相关文章

  1. hdu 5154 Harry and Magical Computer

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5154 Harry and Magical Computer Description In reward ...

  2. hdu 5154 Harry and Magical Computer 拓扑排序

    Harry and Magical Computer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. (简单) HDU 5154 Harry and Magical Computer,图论。

    Description In reward of being yearly outstanding magic student, Harry gets a magical computer. When ...

  4. HDU 5154 Harry and Magical Computer 有向图判环

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5154 题解: 有向图判环. 1.用dfs,正在访问的节点标记为-1,已经访问过的节点标记为1,没有访 ...

  5. 【HDOJ】5154 Harry and Magical Computer

    拓扑排序. /* 5154 */ #include <iostream> #include <cstdio> #include <cstring> #include ...

  6. BC Harry and Magical Computer (拓扑排序)

    Harry and Magical Computer  Accepts: 350  Submissions: 1348  Time Limit: 2000/1000 MS (Java/Others) ...

  7. hdu 5154 拓扑排序

    例题:hdu 5154 链接  http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思是第一行先给出n和m表示有n件事,m个关系,接下来输入m行,每行有 ...

  8. HDU.2612 Find a way (BFS)

    HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...

  9. BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...

随机推荐

  1. python并发爬虫利器tomorrow(一)

    tomorrow是我最近在用的一个爬虫利器,该模块属于第三方的一个模块,使用起来非常的方便,只需要用其中的threads方法作为装饰器去修饰一个普通的函数,既可以达到并发的效果,本篇将用实例来展示to ...

  2. C# 链接webservice报错

    未处理 System.ServiceModel.EndpointNotFoundException  Message="没有终结点对可能接受消息的 http://192.168.0.168/ ...

  3. 04 Go 1.4 Release Notes

    Go 1.4 Release Notes Introduction to Go 1.4 Changes to the language For-range loops Method calls on ...

  4. 洛谷P1455搭配购买

    传送门啦 这是强连通分量与背包的例题 需要注意的就是价值和价格两个数组不要打反了.. 另外 这是双向图!!! #include <iostream> #include <cstdio ...

  5. 使用html+css+js实现计算器

    使用html+css+js实现计算器,开启你的计算之旅吧 效果图: 代码如下,复制即可使用: <!DOCTYPE html><html lang="en"> ...

  6. 泛型 for to/in 遍历 PK 效率;TEnumerator、TEnumerable

    再使用泛型的时候,经常需要用到遍历功能: 只要继承了 TEnumerator 或 TEnumerable 这两个抽象类的 都具有遍历功能. 当然没有继承这两个抽象类的 也具有使用 for in 来遍历 ...

  7. PreparedStatement 查询 In 语句 setArray 等介绍。

    ps = conn.prepareStatement("SELECT tid,jdp_response FROM jdp_tb_trade WHERE tid IN (?) ORDER BY ...

  8. IntelliJ IDEA 去除IDE自动的参数名 提示功能

  9. 20165203 2017-2018-2 《Java程序设计》课程总结

    20165203 2017-2018-2 <Java程序设计>课程总结 一.每周作业及实验报告链接汇总 我期望的师生关系(预备作业一):浅谈一下对师生关系的看法和对自己未来学习和生活的期望 ...

  10. drools7 (一、最简单的例子)

    切记!!! 必须使用jdk1.8 工程目录 引入依赖包,pom.xml <?xml version="1.0" encoding="UTF-8"?> ...