题目地址:POJ 2553

题目意思不好理解。题意是:G图中从v可达的全部点w,也都能够达到v,这种v称为sink。然后升序输出全部的sink。

对于一个强连通分量来说,全部的点都符合这一条件,可是假设这个分量还连接其它分量的话,则肯定都不是sink。所以仅仅须要找出度为0的强连通分量就可以。

代码例如以下:

#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
using namespace std;
#define LL long long
#define pi acos(-1.0)
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double eqs=1e-9;
const int MAXN=5000+10;
int head[MAXN], Ecnt, top, indx, scc;
int low[MAXN], dfn[MAXN], belong[MAXN], instack[MAXN], stk[MAXN], out[MAXN];
struct node
{
int u, v, next;
}edge[1000000];
void add(int u, int v)
{
edge[Ecnt].v=v;
edge[Ecnt].next=head[u];
head[u]=Ecnt++;
}
void tarjan(int u)
{
low[u]=dfn[u]=++indx;
instack[u]=1;
stk[++top]=u;
for(int i=head[u];i!=-1;i=edge[i].next){
int v=edge[i].v;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(instack[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
scc++;
while(1){
int v=stk[top--];
belong[v]=scc;
instack[v]=0;
if(u==v) break;
}
}
}
void init()
{
memset(head,-1,sizeof(head));
memset(dfn,0,sizeof(dfn));
memset(instack,0,sizeof(instack));
memset(out,0,sizeof(out));
Ecnt=top=indx=scc=0;
}
int main()
{
int n, m, i, j, u, v, flag;
while(scanf("%d",&n)!=EOF&&n){
scanf("%d",&m);
init();
while(m--){
scanf("%d%d",&u,&v);
add(u,v);
}
for(i=1;i<=n;i++){
if(!dfn[i]) tarjan(i);
}
for(i=1;i<=n;i++){
for(j=head[i];j!=-1;j=edge[j].next){
v=edge[j].v;
if(belong[i]!=belong[v]){
out[belong[i]]++;
}
}
}
flag=0;
for(i=1;i<=n;i++){
if(out[belong[i]]==0){
if(!flag){
printf("%d",i);
flag=1;
}
else printf(" %d",i);
}
}
puts("");
}
return 0;
}

POJ 2553 The Bottom of a Graph (强连通分量)的更多相关文章

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

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

  2. 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 ...

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

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

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

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

  5. [poj 2553]The Bottom of a Graph[Tarjan强连通分量]

    题意: 求出度为0的强连通分量. 思路: 缩点 具体有两种实现: 1.遍历所有边, 边的两端点不在同一强连通分量的话, 将出发点所在强连通分量出度+1. #include <cstdio> ...

  6. POJ 2553 The Bottom of a Graph(强连通分量的出度)

    题意: 求出图中所有汇点 定义:点v是汇点须满足 --- 对图中任意点u,若v可以到达u则必有u到v的路径:若v不可以到达u,则u到v的路径可有可无. 模板:http://www.cnblogs.co ...

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

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

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

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

  9. poj 2553 The Bottom of a Graph

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

随机推荐

  1. matlab 图片批量读取

    1. 指定的路径 单目录data所有图片 file_path = '.\data\';% 图片目录路径 img_path_list = dir(strcat(file_path,'*.jpg'));% ...

  2. Cocos观察者设计模式和通报机制

    观察员(Observer)模式也称为公告/订阅(Publish/Subscribe)模式.这是 MVC( 模型-视图-控制器)模型的重要组成部分.天气一直讨论的英国最喜欢的话题,近期天气变化几年已成为 ...

  3. Appium - iOS Mac环境结构

    Appium - iOS Mac环境结构 笔者: Max.Bai 时间: 2014/10 1. iOS开发环境的搭建 1.1系统要求 MacOS X 10.7 or higher, 10.9.2 re ...

  4. 使用Advanced Installer将.exe程序重新封装为.msi程序

    原文:使用Advanced Installer将.exe程序重新封装为.msi程序 使用Advanced Installer将.exe程序重新封装为.msi程序 首先安装Advanced instal ...

  5. Unity 4.5.2 for Mac 下载+安装+破解

    因为课程须要, 须要安装unity, 就捣腾了一下, 顺便Mark. 须要准备的资源: Unity 4.5.2官方安装包 : http://netstorage.unity3d.com/unity/u ...

  6. 启示—地点IT高管20在职场心脏经(读书笔记6)

    启示--一个IT高管20在职场心脏经 第七章  关于销售 用"最"来形容公司的销售.能够用上若干的词汇: 最牛,最累,最精,最傻,最有钱,最贱,最能吹.最能装... 1.1  销售 ...

  7. Android项目打包成APK文件

    第一步:右键单击该项目选择Export项目 显演示样例如以下界面:选择Exprot Android Application 第二步:输入项目名称,默认的情况下是原始的项目名称 下一步: 点击 Crea ...

  8. DTD验证XML(转)

    1.内部DTD       最简单的使用DTD的方法是在XML文件的序言部分加入一个DTD描述,加入的位置是紧接在XML处理指示之后.一个包含DTD的XML文件的结构为:    <?xml ve ...

  9. krpano漫游加方向性3D声音(这篇文章已被移到krpano中国网站 krpano360.com)

    需求:      在场景转换视角时.会出现不同方位的声音以及对应的音量变化,也即是将声音视作hotspot.当视角转到该声音热点时,也随之听到声音.官方样例:点击打开链接 本文已经搬迁到下述网址.请点 ...

  10. C文件IO

    ANSI C标准差点儿被全部的操作系统支持,ANSI C标准提供了完好的I/O函数,使用这些I/O操作我们能够控制程序的输入输出.读写系统磁盘文件.本文记录了用户进程I/O缓冲介绍.文件的读写.文件定 ...