题意:定义了一个图的底(bottom),是指在一个图中能够被所有点到达的点,问途中有哪些点是图的底。

首先是同一个强连通分量中的点都能够互相到达,强连通分量中一个点能到达其他点,也必然代表该强连通分量中的点能到达那个点,所以首先强连通,然后此时如果一个点是有出度的,那么它指向的点必然不能到它,所以其实就是求出度为 0 的强连通分量内的点。

 #include<stdio.h>
#include<string.h>
#include<stack>
#include<queue>
using namespace std; const int maxn=5e3+;
const int maxm=1e5+; int head[maxn],point[maxm],nxt[maxm],size;
int n,t,scccnt;
int stx[maxn],low[maxn],scc[maxn];
int od[maxn];
stack<int>S; void init(){
memset(head,-,sizeof(head));
size=;
memset(od,,sizeof(od));
} void add(int a,int b){
point[size]=b;
nxt[size]=head[a];
head[a]=size++;
} void dfs(int s){
stx[s]=low[s]=++t;
S.push(s);
for(int i=head[s];~i;i=nxt[i]){
int j=point[i];
if(!stx[j]){
dfs(j);
low[s]=min(low[s],low[j]);
}
else if(!scc[j]){
low[s]=min(low[s],stx[j]);
}
}
if(low[s]==stx[s]){
scccnt++;
while(){
int u=S.top();S.pop();
scc[u]=scccnt;
if(s==u)break;
}
}
} void setscc(){
memset(stx,,sizeof(stx));
memset(scc,,sizeof(scc));
t=scccnt=;
for(int i=;i<=n;++i)if(!stx[i])dfs(i);
for(int i=;i<=n;++i){
for(int j=head[i];~j;j=nxt[j]){
int k=point[j];
if(scc[i]!=scc[k]){
od[scc[i]]++;
}
}
}
} int main(){
int m;
while(scanf("%d",&n)!=EOF&&n){
scanf("%d",&m);
init();
while(m--){
int a,b;
scanf("%d%d",&a,&b);
add(a,b);
}
setscc();
int cnt=;
for(int i=;i<=n;++i)if(!od[scc[i]]){
if(cnt++)printf(" ");
printf("%d",i);
}
printf("\n");
}
return ;
}

poj2553 强连通的更多相关文章

  1. poj2553 强连通缩点

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10114   Accepted: ...

  2. POJ2553 强连通出度为0的应用

    题意:       给你一个有向图,然后问你有多少个满足要求的点,要求是: 这个点能走到的所有点都能走回这个点,找到所有的这样的点,然后排序输出. 思路:       可以直接一遍强连通缩点,所点之后 ...

  3. POJ2553 The Bottom of a Graph(强连通分量+缩点)

    题目是问,一个有向图有多少个点v满足∀w∈V:(v→w)⇒(w→v). 把图的强连通分量缩点,那么答案显然就是所有出度为0的点. 用Tarjan找强连通分量: #include<cstdio&g ...

  4. 【poj2553】The Bottom of a Graph(强连通分量缩点)

    题目链接:http://poj.org/problem?id=2553 [题意] 给n个点m条边构成一幅图,求出所有的sink点并按顺序输出.sink点是指该点能到达的点反过来又能回到该点. [思路] ...

  5. POJ2553 汇点个数(强连通分量

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12070   Accepted: ...

  6. poj2553 有向图缩点,强连通分量。

    //求这样的sink点:它能达到的点,那个点必能达到他,即(G)={v∈V|任意w∈V:(v→w)推出(w→v)} //我法:tarjan缩点后,遍历点,如果该点到达的点不在同一个强连通中,该点排除, ...

  7. 强连通分量+缩点(poj2553)

    http://poj.org/problem?id=2553 The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total ...

  8. POJ-2552-The Bottom of a Graph 强连通分量

    链接: https://vjudge.net/problem/POJ-2553 题意: We will use the following (standard) definitions from gr ...

  9. HDU5934 强连通分量

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5934 根据距离关系建边 对于强连通分量来说,只需引爆话费最小的炸弹即可引爆整个强连通分量 将所有的强连通分 ...

随机推荐

  1. ModuleWorks免费下载使用方法大全

    ModuleWorks为模拟机器的工具运转及(或)机床和车床材料的搬运提供了一整套解决方案. 模拟技术可以识别潜在的碰撞问题,允许在NC代码生成前进行除错检查,并且渐渐成为CAM处理方面必不可少的解决 ...

  2. 看项目得到info_freeCsdn-01闪屏页面

    /** * 渐变展示启动屏 */ private void startAnimation() { Animation aa = new Animation() { }; aa.setDuration( ...

  3. C语言输出规定长度的整数,不够位数前面补零

    今天在做ACM题目的时候,遇到了这么一个问题,还真别说,这个以前真的没用过,当时就傻掉了,还好这个世界有Google,通过搜索了解了输出这种格式的C语言实现方法.但是没有找到C++的实现方法,希望知道 ...

  4. Access 中数据库操作时提示from子句语法错误

    问题:如果在Access 中数据库操作时提示from子句语法错误原因:语句中某一单词为Access中的关键字.如:select * from user.其中user就是一关键字.解决:用中括号[]将其 ...

  5. Android-LogCat日志工具(一)

    LogCat : Android中一个命令行工具,可以用于得到程序的log信息. 就像你知道一个人的日志.航程,你可以无时无刻知道一个人在干什么. 而LogCat , 就是程序的日志.通过日志,你可以 ...

  6. jQuery 自定义扩展,与$冲突处理

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. Pattern和Matcher

    java util本身提供了Pattern和Matcher(java.util.regex.Pattern,Matcher),两个类均是与正则表达式相关的类,其中: java.util.regex是一 ...

  8. (转)phoneGap-Android开发环境搭建

    (原)http://www.cnblogs.com/shawn-xie/archive/2012/08/15/2638480.html phoneGap-Android开发环境搭建   一.安装 在安 ...

  9. C++的三种继承方式简述

    C++对父类(也称基类)的继承有三种方式,分别为:public继承.protected继承.private继承.三种继承方式的不同在于继承之后子类的成员函数的"可继承性质". 在说 ...

  10. C++读入二进制数并转换为十进制输出

    题目描述 已知一个只包含0和1的二进制数,长度不大于10,将其转换为十进制并输出. 输入描述 输入一个二进制整数n,其长度不大于10 输出描述 输出转换后的十进制数,占一行 样例输入 样例输出 sol ...