思路待整理

#include<cstdio> #include<iostream> #include<cstring> #include<vector> #include<cmath> #define maxn 10001
using namespace std; int n,m,vis[maxn],low[maxn],dfn[maxn]; vector<int> fuck[maxn]; int sum,ret; int minn(int x,int y) { if(x>y) return y; else return x; } void init() { sum=0; ret=1; for(int i=1;i<=n;i++) fuck[i].clear(),low[i]=dfn[i]=vis[i]=0; } void dfs(int pos) { vis[pos]=1; low[pos]=dfn[pos]=ret++; for(int i=0;i<fuck[pos].size();i++) { int temp=fuck[pos][i]; if(vis[temp]==0) dfs(temp); if(vis[temp]==1) low[pos]=minn(low[pos],low[temp]);//回溯处理 } if(low[pos]==dfn[pos]) sum++; //回溯处理 } int main() { while(cin>>n>>m&&(m+n)) { init(); while(m--) { int x,y; cin>>x>>y; if(x==y) continue; fuck[x].push_back(y); } for(int i=1;i<=n;i++) if(!vis[i]) dfs(i); if(sum==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案