标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 499 Accepted Submission(s): 233
#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[101][101]; int vis[101]; int flag[101]; int main() { int n,m; while(cin>>n>>m) { memset(map,0,sizeof(map)); memset(vis,0,sizeof(vis)); memset(flag,0,sizeof(flag)); int a,b; for(int i=0;i<m;i++) { cin>>a>>b; map[b-1][a-1]=1; flag[a-1]=1; } queue<int> q; for(int i=0;i<n;i++) { if(flag[i]==0) { q.push(i); vis[i]=1; } } int now; int next; while(!q.empty()) { now=q.front(); for(int i=0;i<n;i++) { if(map[now][i]==1) { if(vis[i]==1) continue; q.push(i); vis[i]=1; } } q.pop(); } int flag1=0; for(int i=0;i<n;i++) { if(vis[i]==0) { flag1=1; break; } } if(flag1==1) cout<<"NO"<<endl; else cout<<"YES"<<endl; } }
HDU 5154 Harry and Magical Computer bfs
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4215538.html