标签:
从一个点正向访问的所有的点,也能从这个点反向访问到所有的点,则yes,否则no;
#include<iostream> #include<cstring> #include<vector> #define maxn 100000+5 using namespace std; int n,m; vector<int>zh[maxn]; vector<int>fa[maxn]; int visit[10000+5]; int sum1,sum2; void dfsz(int x) { visit[x]=1; for(int i=0;i<zh[x].size();i++) { if(!visit[zh[x][i]]) dfsz(zh[x][i]),sum1++; } } void dfsf(int x) { visit[x]=1; for(int i=0;i<fa[x].size();i++) { if(!visit[fa[x][i]]) dfsf(fa[x][i]),sum2++; } } int main() { while(cin>>n>>m) { if(!n&&!m) break; for(int i=0;i<maxn;i++) zh[i].clear(),fa[i].clear(); while(m--) { int x,y; cin>>x>>y; zh[x].push_back(y); fa[y].push_back(x); } sum1=1;sum2=1; fill(visit,visit+n+1,0); dfsz(1); fill(visit,visit+n+1,0); dfsf(1); if(sum1==n&&sum2==n) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
标签:
原文地址:http://blog.csdn.net/zafkiel_nightmare/article/details/45935717