题意:

求出图中所有汇点

定义:点v是汇点须满足 --- 对图中任意点u,若v可以到达u则必有u到v的路径;若v不可以到达u,则u到v的路径可有可无。

模板:http://www.cnblogs.com/Jadon97/p/8328750.html

分析:

很显然, 图中强连通分量中所有的点属性都是一样的, 要么都是汇点, 要么都不是。

如果有一个强连通分量A的边连向强连通分量B, 那么A一定不是汇点, 因为B不会有边连向A(如果有的话A、B就是同一个强连通分量了)。

求出所有强连通分量, 然后再求一下出度即可

#include <stack>
#include <cstdio>
#include <vector>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = ;
vector<int> G[maxn];
int n , m;
int dfn[maxn], low[maxn], color[maxn], out_degree[maxn];
int dfs_num = , col_num = ;
bool vis[maxn];//标记元素是否在栈中
stack<int> s;
void Tarjan(int u)
{
dfn[ u ] = dfs_num;
low[ u ] = dfs_num++;
vis[u] = true; //标记访问
s.push(u); // 入栈
for(int i = ; i < G[u].size(); i++)
{
int v = G[u][i];
if( ! dfn[v])
{
Tarjan( v );
low[u] = min(low[v], low[u]);
}
else if(vis[v]) //如果在v栈中 , 更新low[u]
{
low[u] = min(low[u], dfn[v]);
}
}
if(dfn[u] == low[u])
{
vis[u] = false;
color[u] = col_num;
int t;
for(;;){
int t = s.top(); s.pop();
color[t] = col_num;
vis[t] = false;
if(t == u) break;
}
col_num++;
}
}
int main()
{
while(~scanf("%d %d", &n,&m))
{
if(n == ) break;
for(int i = ; i < maxn; i++) G[i].clear();
memset(dfn, , sizeof(dfn));
memset(vis, , sizeof(vis));
memset(low, , sizeof(low));
memset(color, , sizeof(color));
memset( out_degree, ,sizeof(out_degree));
dfs_num = , col_num = ;
for(int i = ; i < m; i++)
{
int u , v;
scanf("%d %d", &u, &v);
G[u].push_back(v);
} for(int i = ; i <= n; i++){
if(!dfn[i])
Tarjan(i);
} for(int u = ; u <= n; u++){ //
for(int i = ; i < G[u].size(); i++){//枚举每一条边
int v = G[u][i];
if(color[u] != color[v]){ //如果有一条u到v的边, 但u,v不是同一个强连通分量, 说明u所在的强连通分量有一条出边指向v, u中都不是题目所求
out_degree[color[u]]++;
}
}
} int cnt = , ans[maxn];
for(int u = ; u <= n; u++){
if(out_degree[color[u]] == ) ans[cnt++] = u;
}
printf("%d",ans[]);
for(int i = ;i < cnt; i++) printf(" %d", ans[i]); puts("");
}
return ;
}

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 2553 The Bottom of a Graph (强连通分量)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. visual studio各版本下载

    软件包括以下几种: cn_visual_studio_2010_ultimate_x86_dvd_532347.part1.rar cn_visual_studio_2010_ultimate_x86 ...

  2. css width

    转载:http://blog.csdn.net/dddddz/article/details/8631655

  3. Histogram LightOJ - 1083

    Histogram LightOJ - 1083 题意:给出一个直方图,由n个长条组成,它们的x轴上坐标分别为1-n,读入n之后读入的一行中,第i个表示x轴上坐标为i的长条长度.求直方图最大的正方形面 ...

  4. JavaScript-获取当前元素的相关元素或节点--方法总结

    1.获取当前元素中的第一个子节点 document.getElementById("uu").firstChild 2.获取当前元素中的第一个子元素 document.getEle ...

  5. TPS763xxDBV线性稳压器

    DC DC converter 是直流变换器,因为直流不能通过变压器改变电压,要将直流电压通过振荡变成交流电压,再通过变压器或斩波器将电压升高或降低,再经滤波变成所需的电压.而voltage regu ...

  6. Jquary基础

    基本知识: 就是一个JS函数包 选择器:基本选择器: 基本:ID选择器 “#” , Class选择器 “.”,标签选择器 “标签名” 组合:并列用“,”隔开   后代用空格隔开 过滤选择器:基本过滤: ...

  7. Kotlin学习的一些笔记

    Introduction 写在前面 关于本书 这本书适合你吗? 关于作者 介绍 什么是Kotlin? 我们通过Kotlin得到什么 准备工作 Android Studio 安装Kotlin插件 创建一 ...

  8. http://www.360doc.com/content/10/0928/12/11991_57014502.shtml

    http://www.360doc.com/content/10/0928/12/11991_57014502.shtml

  9. 两个已排序数组的合并-C语言

    最近在纸上写一个已排序数组的合并时,花了超过预期的时间.仔细想想,这种要放到毕业找工作那会两下就出来了,原因还在于工作后对基础没有重视,疏于练习. 说开一点,现在搜索引擎的发达确实给问题的解决带来了便 ...

  10. TCP/IP详解之IP协议

    1.IP协议 IP协议是TCP/IP协议的核心,所有的TCP,UDP,IMCP,IGCP的数据都以IP数据格式传输.要注意的是,IP不是可靠的协议,这是说,IP协议没有提供一种数据未传达以后的处理机制 ...