poj 2553 The Bottom of a Graph
来源:互联网 发布:南京栖霞区网络问政 编辑:程序博客网 时间:2024/05/16 06:36
题意:
给一个定义bottom(G)={v∈V|∀w∈V:(v→w)⇒(w→v)},意思就是在一个有向图中存在一种点v1,这种点满足:v1可达的点集V中所有点,都有一条路径回到v1。先要找出所有的点,按字典序输出。
思路:
找到出度为0的强联通分量,按字典叙输出其中的点。
#include<iostream>using namespace std;const int MAXN =10001;int DFN[MAXN];int LOW[MAXN];int instack[MAXN];int Stap[MAXN];int Belong[MAXN];int num[MAXN];int count[MAXN];struct edge{int v,next;}vetex[50001];int head[MAXN];int Stop,Bcnt,Dindex,N,k;void add(int a,int b){vetex[k].v = b;vetex[k].next = head[a];head[a] = k;k++;}void tarjan(int i){int j;DFN[i]=LOW[i]=++Dindex;instack[i]=true;Stap[++Stop]=i;for (int k=head[i];k;k=vetex[k].next){j=vetex[k].v;if (!DFN[j]){tarjan(j);if (LOW[j]<LOW[i])LOW[i]=LOW[j];}else if (instack[j] && DFN[j]<LOW[i])LOW[i]=DFN[j];}if (DFN[i]==LOW[i]){Bcnt++;do{j=Stap[Stop--];instack[j]=false;Belong[j]=Bcnt;}while (j!=i);}}void solve(){int i;Stop=Bcnt=Dindex=0;for (i=1;i<=N;i++)if (!DFN[i])tarjan(i);}int main(){int E;while(cin>>N){if(N==0)break;cin>>E;k=1;memset(count,0,sizeof(count));memset(num,0,sizeof(num));memset(head,false,sizeof(head));memset(DFN,0,sizeof(DFN));for(int i=1;i!=E+1;i++){int a,b;cin>>a>>b;add(a,b);}solve();//cout<<Bcnt<<endl;for(int i=1;i!=N+1;i++){int t = Belong[i];for(int k = head[i];k;k=vetex[k].next)if(t!=Belong[vetex[k].v])num[t]++;if(num[t]!=0)count[t]++;}//for(int i=1;i!=Bcnt+1;i++)//cout<<count[i]<<" ";int flag(0);for(int i=1;i!=N+1;i++){int t = Belong[i];if(count[t]==0){if(flag==0)cout<<i;elsecout<<" "<<i;flag=1;}}cout<<endl;}return 0;}
- POJ 2553 The Bottom of A Graph
- poj 2553 The Bottom of a Graph
- poj 2553 The Bottom of a Graph
- poj 2553 The Bottom of a Graph
- poj 2553 The Bottom of a Graph
- POJ 2553-The Bottom of a Graph
- poj 2553 The Bottom of a Graph
- POJ-2553 The Bottom of a Graph
- POJ 2553 The Bottom of a Graph
- POJ 2553The Bottom of a Graph
- POJ 2553 The Bottom of a Graph .
- poj 2553 The Bottom of a Graph
- POJ 2553 The Bottom of a Graph
- POJ 2553 The Bottom of a Graph
- poj 2553 The Bottom of a Graph
- POJ 2553 The Bottom of a Graph
- The Bottom of a Graph POJ
- poj 2553 The Bottom of a Graph(Tarjan~)
- 将 C++ 的成员函数作为回调函数
- 第十一章安装RPM包或者安装源码包
- 【HDU1686】Oulipo 思路+解题报告+代码+KMP算法个人理解 【0.5%达成】
- 第十二章 学习shell脚本之前的基础知识
- SGU 185 Two shortest 最短路+最小费用最大流 或者 最短路+最大流
- poj 2553 The Bottom of a Graph
- 在敏捷开发中如何维护文档
- SurfaceView和View最本质的区别
- 深圳手付通java面试题
- crontab使用说明及例子程序
- 华为boss力荐公司高层看的一篇文章,真的很经典!!![转载]
- commons-logging+log4j 简单的完整的日志操作实例
- 百度快照出问题投诉有没有用?
- rtems 4.11 ubuntu 12.04