标签:
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> #include<cstring> #include<vector> using namespace std; #define maxn 10005 #define N 10045 vector<vector<int> >G; int dfs[N],w[N],low[N],S[N]; int k,kk,ans,anss; int n; void q() { G.clear(); G.resize(n+10); memset(dfs,0,sizeof(dfs)); memset(low,0,sizeof(low)); memset(S,0,sizeof(S)); memset(w,0,sizeof(w)); ans=anss=k=kk=0; } void qq(int u) { dfs[u]=low[u]=++k; S[kk++]=u; w[u]=1; int len=G[u].size(),v; for(int i=0; i<len; i++) { v=G[u][i]; if(!dfs[v]) { qq(v); low[u]=min(low[u],low[v]); } else if(w[v]) low[u]=min(low[u],dfs[v]); } if(low[u]==dfs[u]) { anss++; do { ans++; //printf("%d %d\n",u,v); v=S[--kk]; w[v]=0; } while(u!=v); } } int main() { int m,e,f; while(scanf("%d%d",&n,&m),n||m) { q(); for(int i=0; i<m; i++) { scanf("%d%d",&e,&f); G[e].push_back(f); } qq(1); // printf(" %d %d\n",ans,anss); if(ans==n&&anss==1) printf("Yes\n"); else printf("No\n"); } return 0; }
http://acm.hdu.edu.cn/showproblem.php?pid=1269
标签:
原文地址:http://www.cnblogs.com/a719525932/p/5671141.html