HDU 5154 Harry and Magical Computer (Floyd)
来源:互联网 发布:淘宝商城摩托车配件 编辑:程序博客网 时间:2024/06/05 18:17
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int maps[105][105];int n,m;int main(){ while(~scanf("%d%d",&n,&m)) { memset(maps,0,sizeof(maps)); int flag=0; for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); //if(x==y) flag=1; maps[x][y]=1; } for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(maps[i][j]!=1&&maps[i][k]==1&&maps[k][j]==1) { maps[i][j]=1; } } } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { //if(i==j) continue; //else { if(maps[i][j]==1&&maps[j][i]==1) { flag=1; } } } } if(flag==1) printf("NO\n"); else printf("YES\n"); }}
Harry and Magical Computer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2451 Accepted Submission(s): 947
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
For each test case, there are two numbers n m on the first line, indicates the number processes and the number of dependencies.
The next following m lines, each line contains two numbers a b, indicates a dependencies (a, b).
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).
If the computer can finish all the process print "YES" (Without quotes).
Else print "NO" (Without quotes).
Sample Input
3 23 12 13 33 22 11 3
Sample Output
YESNO
Source
BestCoder Round #25
Recommend
heyang | We have carefully selected several similar problems for you: 5981 5980 5979 5978 5977
0 0
- HDU 5154 Harry and Magical Computer (Floyd)
- hdu 5154 Harry and Magical Computer
- Harry and Magical Computer (HDU 5154)
- hdu 5154 Harry and Magical Computer
- HDU 5154 Harry and Magical Computer
- hdu 5154 Harry and Magical Computer
- HDU 5154 Harry and Magical Computer (BFS)
- HDOJ 5154 Harry and Magical Computer floyd判环
- hdu 5154 Harry and Magical Computer(拓扑排序)
- [BestCoder] Round #25 1001 - Harry and Magical Computer | HDU 5154
- HDU 5154 Harry and Magical Computer 拓扑排序
- hdu 5154 Harry and Magical Computer(BestCoder Round #25)
- HDU 5154 Harry and Magical Computer 拓扑排序
- HDU 5154 Harry and Magical Computer【逆拓扑】
- HDU 5154 Harry and Magical Computer(找环)
- hdu 5154 Harry and Magical Computer(拓扑排序)
- hdu 5154 Harry and Magical Computer(拓扑排序)
- HDU 5154 Harry and Magical Computer (拓扑排序)
- LeetCode Learning 5
- 记一次遇到的文件乱码的问题
- 智能家居设计
- Codeforces 633C Spy Syndrome 2 字典树
- 第一天博客
- HDU 5154 Harry and Magical Computer (Floyd)
- C#学习笔记之六 类定义中static关键字的用法暨C#中静态变量的意义与使用
- R_2.创建数据集
- 【Studio】导入其他项目卡死
- Effective Java(Item: 38 to 56)
- 使用Form表单向远处的网页提交信息代码__Cookie方式
- C语言中的指针数组与数组指针的理解
- 图的遍历(dfs、bfs、最短路、最小生成树、拓扑排序)
- js实现window 弹窗小案例