POJ 2186
来源:互联网 发布:县医院 网络图片图 编辑:程序博客网 时间:2024/06/05 00:27
我忽视了如果里面不知一个out0的DAG图,那样显然不能满足
#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<vector>using namespace std;const int maxn=20000+10;int n,m;vector<int> G[maxn];stack<int> S;int dfs_clock,scc_cnt;int pre[maxn],low[maxn],sccno[maxn];bool in0[maxn],out0[maxn];void dfs(int u){ pre[u]=low[u]=++dfs_clock; S.push(u); for(int i=0;i<G[u].size();i++) { int v=G[u][i]; if(!pre[v]) { dfs(v); low[u]=min(low[u],low[v]); } else if(!sccno[v]) low[u]=min(low[u],pre[v]); } if(low[u]==pre[u])//强连通分量起点 { scc_cnt++; while(true) { int x= S.top(); S.pop(); sccno[x]=scc_cnt; if(x==u) break; } }}void find_scc(int n){ scc_cnt=dfs_clock=0; memset(pre,0,sizeof(pre)); memset(sccno,0,sizeof(sccno)); for(int i=0;i<n;i++) if(!pre[i]) dfs(i);}int main(){ scanf("%d%d",&n,&m); for(int i=0;i<n;i++)G[i].clear(); int u,v; for(int i=0;i<m;i++){ scanf("%d%d",&u,&v); G[u-1].push_back(v-1); } find_scc(n); for(int i=1;i<=scc_cnt;i++)out0[i]=true; for(int u=0;u<n;u++){ for(int i=0;i<G[u].size();i++){ int v=G[u][i]; if(sccno[u]!=sccno[v]){out0[sccno[u]]=false;break;} } } int cnt=0; for(int i=1;i<=scc_cnt;i++){ if(out0[i])cnt++; } if(cnt!=1){ printf("0\n"); return 0; } int ans=0; for(int i=0;i<n;i++){ if(out0[sccno[i]])ans++; } printf("%d\n",ans); return 0;}
0 0
- POJ 2186
- poj 2186
- poj 2186
- poj 2186
- POJ 2186
- POJ 2186
- poj 2186
- POJ 2186
- POJ 2186
- poj 2186
- 【POJ】2186
- POJ 2186 Popular Cows
- poj 2186 Popular Cows
- poj 2186 tarjan算法
- poj 2186 Popular Cows
- poj 2186 Popular Cows
- poj 2186 Popular Cows
- poj 2186 Popular Cows
- windows平台下安装python的setuptools工具
- SI与EMI(二)
- iOS GCD实现
- 如何用java 5分钟实现一个最简单的mysql代理服务器?
- 调用系统功能,邮件发送方式,各种文件打开方法-Intent的详解
- POJ 2186
- Office 可以插入和保存的图形文件类型
- poj 1926 All in all
- 在 Sql Server 中实现 UrlDecode
- HDU-1874-畅通工程续【最短路】
- eclipse使用
- 12.屏幕高斯模糊
- 自定义view的一些记录
- scanf和gets的区别