Legal or Not
来源:互联网 发布:福建都是用晨曦软件 编辑:程序博客网 时间:2024/05/19 21:41
拓扑排序基础题 点击打开链接
#include < iostream>#include < cstring >#include < queue >#define N 105using namespace std; int g[N][N], d[ N ];int tsort(int n){int i,j,k;queue<int> que;for(i=0;i<n;i++)if(d[i]==0) que.push(i);while(!que.empty()){k=que.front();que.pop();for(j=0;j<n;j++){if(g[k][j]){d[j]-=1 , g[k][j]=0;if(d[j]==0) que.push(j);}}}for(i=0;i<n;i++)if(d[i]>0) return 0;return 1;}int main (){//freopen("ts.txt","r",stdin);int n,m,i,x,y;while(cin>>n>>m,n||m){memset(g,0,sizeof(g));memset(d,0,sizeof(d));for(i=0;i<m;i++){cin>>x>>y;if(g[x][y]) continue;g[x][y]=1,d[y]++;}if(tsort(n)) cout<<"YES"<<endl;else cout<<"NO" <<endl;}return 0;}
- Legal or Not
- Legal or Not HDU
- TOJ3650 Legal or Not
- C - Legal or Not
- Legal or Not
- Legal or Not
- HDU3342---Legal or Not
- Legal or Not
- Legal or Not
- Legal or Not
- 3342 Legal or Not
- Legal or Not
- Legal or Not(HDU_3342)
- HDU3342-Legal or Not
- HDU3342-Legal or Not
- hdu Legal or Not
- legal or not
- Legal or Not HDU
- No entity found for query
- 【rose】rose初始化
- 调试狂牛加密视频OD设置
- poj 1200 Crazy Search
- APK反破解之三:NDK编译.so动态库
- Legal or Not
- 收集常用的 cocos2d-x 游戏开发工具
- string常用操作(更新)
- 完全卸载oracle11g步骤
- iOS_如何使用UIAutomation进行iOS 自动化测试(Part I)
- Tortoiser三十集脱壳教程
- Airport Seoul 2009
- 打靶问题
- poj 2576二维01背包