图论之强连通复习开始- -

题目大意:给你一个有向图,要你求出这样的点集:从这个点出发能到达的点,一定能回到这个点

思路:强连通分量里的显然都可以互相到达 那就一起考虑,缩点后如果一个点有出边,一定不在点集内,因为缩点后是DAG,无环,因此一定不能回到原来的点,所以找到出度为0的点即可

#include<cstdio>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<iostream>

#include<queue>

#define maxn 90000

#define inf 0x3f3f3f3f

using namespace std;

int head[maxn],next[maxn],point[maxn],now=0;

int dfn[maxn],low[maxn],time,col,stack[maxn];

int top,belong[maxn],out[maxn];

bool instack[maxn];

void add(int x,int y)

{

next[++now]=head[x];

head[x]=now;

point[now]=y;

}

void tarjan(int k)

{

int u;

dfn[k]=low[k]=++time;

instack[k]=1;

stack[++top]=k;

for(int i=head[k];i;i=next[i])

{

u=point[i];

if(dfn[u]==0)

{

tarjan(u);

low[k]=min(low[u],low[k]);

}

else if(instack[u])low[k]=min(low[k],low[u]);

}

if(low[k]==dfn[k])

{

++col;

do

{

u=stack[top--];

instack[u]=0;

belong[u]=col;

}while(u!=k);

}

}

int main()

{

int n,m,x,y;

while(1)

{

scanf("%d",&n);

if(n==0)break;

scanf("%d",&m);

now=0;memset(head,0,sizeof(head));

top=0;memset(instack,0,sizeof(instack));

memset(out,0,sizeof(out));

memset(dfn,0,sizeof(dfn));

for(int i=1;i<=m;i++)

{

scanf("%d%d",&x,&y);

add(x,y);

}

for(int i=1;i<=n;i++)if(dfn[i]==0)tarjan(i);

for(int i=1;i<=n;i++)

{

for(int j=head[i];j;j=next[j])

{

int u=point[j];

if(belong[i]!=belong[u])out[belong[i]]++;

}

}

int flag=1;

for(int i=1;i<=n;i++)

{

if(flag && out[belong[i]]==0)

{

printf("%d",i);

flag^=flag;

}

else if(out[belong[i]]==0)printf(" %d",i);

}

printf("\n");

}

return 0;

}

POJ 2553 The Bottom of a Graph 【scc tarjan】的更多相关文章

  1. poj 2553 The Bottom of a Graph【强连通分量求汇点个数】

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

  2. POJ 2553 The Bottom of a Graph(强连通分量)

    POJ 2553 The Bottom of a Graph 题目链接 题意:给定一个有向图,求出度为0的强连通分量 思路:缩点搞就可以 代码: #include <cstdio> #in ...

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

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

  4. POJ 2553 The Bottom of a Graph (Tarjan)

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

  5. POJ 2553 The Bottom of a Graph (强连通分量)

    题目地址:POJ 2553 题目意思不好理解.题意是:G图中从v可达的全部点w,也都能够达到v,这种v称为sink.然后升序输出全部的sink. 对于一个强连通分量来说,全部的点都符合这一条件,可是假 ...

  6. POJ 2553 The Bottom of a Graph Tarjan找环缩点(题解解释输入)

    Description We will use the following (standard) definitions from graph theory. Let V be a nonempty ...

  7. poj 2553 The Bottom of a Graph : tarjan O(n) 存环中的点

    /** problem: http://poj.org/problem?id=2553 将所有出度为0环中的点排序输出即可. **/ #include<stdio.h> #include& ...

  8. poj - 2186 Popular Cows && poj - 2553 The Bottom of a Graph (强连通)

    http://poj.org/problem?id=2186 给定n头牛,m个关系,每个关系a,b表示a认为b是受欢迎的,但是不代表b认为a是受欢迎的,关系之间还有传递性,假如a->b,b-&g ...

  9. poj 2553 The Bottom of a Graph

    求解的是有向图中满足“自己可达的顶点都能到达自己”的顶点个数如果强连通分量中某个顶点,还能到达分量外的顶点,则该连通分量不满足要求// 因此,本题要求的是将强连通分量缩点后所构造的新图中出度为0的顶点 ...

随机推荐

  1. RHEL 6.5---SVN服务实现过程

    主机名 IP地址  master 192.168.30.130 slave 192.168.30.131 安装 [root@master ~]# yum install -y subversion h ...

  2. spring mvc支持跨域请求

    @WebFilter(urlPatterns = "/*", filterName = "corsFilter") public class CorsFilte ...

  3. 9.JAVA-抽象类定义

    1.抽象类 抽象类,用来表示一个抽象概念. 是一种只能定义类型,而不能产生对象的类,所以定义了抽象类则必须有子类的出现. 抽象类的好处在于能够明确地定义子类需要覆写的方法 抽象类需要使用abstrac ...

  4. LN : leetcode 416 Partition Equal Subset Sum

    lc 416 Partition Equal Subset Sum 416 Partition Equal Subset Sum Given a non-empty array containing ...

  5. CF750D New Year and Fireworks

    题意: 放烟花. 一个烟花从某一起点开始,沿着当前方向移动指定数量的格子之后爆炸分成两部分,分别沿着当前方向的左上和右上方向移动.而每一部分再沿着当前方向移动指定数量的格子之后爆炸分成两部分.如此递归 ...

  6. Macbook air 上打开cocoscreator出错

    Error: EROFS: read-only file system, open '/Volumes/Cocos Creator/CocosCreator.app/Contents/Resource ...

  7. TabLayout.Tab(自定义)点击事件

    TabLayout是官方design包中的一个布局控件,这里不介绍它的基本使用,只是解决Tab(自定义)点击事件. //获取Tab的数量 Int tabCount = tabLayout.getTab ...

  8. mac下iterm2配置安装,通过expact实现保存账号,及通过跳板登陆配置

    在参考了几款mac不错的ssh工具外,最终选择使用iterm2.本来打算用FinalShell,安装后发现其icon在访达中根本不现实,而且每次访问还需要输入管理员账号密码,强迫症根本受不了... 官 ...

  9. 第一次提交代码到github时经常遇到的问题

    最近两年在OpenStack方面做了一些工作,写了一些实验性的plugin. 本着Open Source的共享精神,想尝试提交到github,以便他人能下载使用. 当你注册完github帐号之后,点击 ...

  10. SEO 第八章

    SEO第八章 本次课目标: 1.  网站外部优化的外链优化 2.  网站流量分析 1.  什么叫做外链? 外链也叫反向链接,指的是从别的网站指向我自己的网站的链接. 2.  外链的作用? l  外链可 ...