POJ 2553
来源:互联网 发布:淘宝店铺流失人数 编辑:程序博客网 时间:2024/06/05 02:32
这道题还是和其他题目相似,没有什么差别和软用
#include<cstdio>#include<cstring>#include<algorithm>#include<stack>#include<vector>using namespace std;const int maxn=5000+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);}bool on[maxn];int main(){ while(scanf("%d",&n)){ if(!n){break;} scanf("%d",&m); for(int i=0;i<n;i++)G[i].clear(); for(int i=0;i<m;i++){ int u,v; scanf("%d%d",&u,&v); G[u-1].push_back(v-1); } find_scc(n); memset(out0+1,true,scc_cnt); memset(on,false,n); 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; } } } int cnt=0; for(int i=0;i<n;i++){ if(out0[sccno[i]]){ on[i]=true; cnt++; } } int flag=0; for(int i=0;i<n;i++){ if(on[i]){ flag++; if(flag!=cnt) printf("%d ",i+1); else printf("%d\n",i+1); } } if(!cnt) printf("\n"); } return 0;}
0 0
- POJ 2553
- poj 2553
- POJ 2553
- POJ 2553
- poj 2553
- POJ 2553
- poj 2553 tarjan算法
- POJ 2553-题意很重要...
- poj 2553 tarjan
- poj 2553 强连通
- poj 2553 强连通
- poj 2553
- POJ 2553&&ZOJ 1979
- poj 2553 Tarjan
- poj-2553 Frogger
- POJ 2553 Tarjan
- POJ
- poj
- mongodb的一些基本命令
- 在Unity3D中使用C#如何进行XML文件的读写
- Zdialog插件关闭事件
- 使用material design组件遇到的一些问题
- Excel中度转度分秒
- POJ 2553
- Android Fragment 你应该知道的一切
- 【POJ】3630 - Phone List(字典树(静态建树))
- Eclipse配置多个jdk
- 数据库记录2
- emacs替换查找当中大小写敏感
- Linux错误机制
- 二分_F
- Lucene教程(二) 搜索