九度 题目1448:Legal or Not
来源:互联网 发布:微盘交易软件 编辑:程序博客网 时间:2024/06/08 05:24
判断是否存在环的问题,本文采用的是拓扑排序,如果输出的节点少于N,则形成了环,和之前的1449几乎是一样的代码
题目链接http://ac.jobdu.com/problem.php?pid=1448
转载请注明本文地址http://blog.csdn.net/yangnanhai93/article/details/41226369
#include <iostream>#include <memory.h>#include <queue>using namespace std;int A[100],MapCount[100][100];bool TopoSort(int n){ queue<int> qu; for(int i=0;i<n;i++) if(A[i]==0) qu.push(i); int count=0; while(!qu.empty()) { int front=qu.front(); qu.pop(); count++; for (int i=0;i<n;i++) { if(MapCount[front][i]) { A[i]--; if(A[i]==0) qu.push(i); } } } if(count==n) return true; else return false;}int main(){ //freopen("data.in","r",stdin); int m,n,x,y; while(cin>>m>>n&&m) { memset(A,0,sizeof(A)); memset(MapCount,0,sizeof(MapCount)); for(int i=0;i<n;i++) { cin>>x>>y; MapCount[x][y]=1; } for(int i=0;i<m;i++) for(int j=0;j<m;j++) if(MapCount[i][j]!=0) A[j]++; if(TopoSort(m)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}/************************************************************** Problem: 1448 User: vincent_ynh Language: C++ Result: Accepted Time:10 ms Memory:1560 kb****************************************************************/
0 0
- 九度 题目1448:Legal or Not
- 九度 题目1448:Legal or Not
- 九度oj 题目1448:Legal or Not
- 九度OJ题目1448:Legal or Not
- 九度1448:Legal or Not
- 九度OJ-1448:Legal or Not
- 题目1448:Legal or Not
- 题目1448:Legal or Not
- 题目1448:Legal or Not
- 题目1448:Legal or Not
- 题目1448:Legal or Not
- 题目1448:Legal or Not
- 九度OJ 题目1448:Legal or Not (拓扑排序)
- 题目1448:Legal or Not 【拓扑排序】
- Jobdu 题目1448:Legal or Not
- HDOJ 题目3342Legal or Not(拓扑排序)
- Legal or Not
- Legal or Not HDU
- Android项目之HomeHealth基础学习1:Baseadapter
- .net中XML的详细解析
- Android_3 事件响应
- POJ 1661 hlep Jimmy 题解
- wordpress模板插件收集
- 九度 题目1448:Legal or Not
- Android - 位置定位(Location)服务(Service)类的基本操作
- MATLAB入门教程,比较全面
- 在code::block中使用boost库
- Redis 3.0 源码解析---底层数据结构分析(1)
- 安卓项目有感叹号
- d3d载入x网格
- Longest Valid Parentheses
- 软件版本中的Alpha,Beta,RC,Trial是什么意思?