标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define esp 0.00000000001 const int N=2e3+10,M=1e6+10,inf=1e9; int n,m; vector<int>edge[N]; int du[N]; int main() { while(~scanf("%d%d",&n,&m)) { queue<int>q; memset(du,0,sizeof(du)); for(int i=0;i<=n;i++) edge[i].clear(); int ans=0; for(int i=1;i<=m;i++) { int u,v; scanf("%d%d",&u,&v); edge[u].push_back(v); du[v]++; } for(int i=1;i<=n;i++) { if(!du[i])q.push(i); } while(!q.empty()) { int v=q.front(); q.pop(); ans++; for(int i=0;i<edge[v].size();i++) { du[edge[v][i]]--; if(!du[edge[v][i]]) q.push(edge[v][i]); } } if(ans==n) printf("YES\n"); else printf("NO\n"); } return 0; }
hdu 5154 Harry and Magical Computer 拓扑排序
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5982254.html