题意:

求出图中所有汇点

定义:点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. iOS [CIContext initWithOptions:]: unrecognized selector sent to instance 模拟器 iOS 8.4

    在模拟器(iPhone 4s,iOS 8.4)中运行应用时, 应用crash在了使用CIContext(options:nil) 这个API的一个纯Swift第三方库. StackOverFlow的解 ...

  2. 从一个n位数中选出m位按顺序组成新数并使其最大 || Erasing and Winning UVA - 11491

    就是从n位数中取出n-d个数字按顺序排成一排组成一个新数使得其最大 算法: 从前往后确定每一位.找第i位时,要求后面留下d-i位的空间, 因此第i位应该从第i-1位原来位置+1到第d+i位寻找 用线段 ...

  3. hibernate Day1 案例代码

    1.创建Person类 package com.icss.pojo; public class Person { private int uid; private String uname; priv ...

  4. Eclipse安装jad反编译插件(在线安装)

    Help→Eclipse Marketplace→Find→jad 然后等安装完成重启eclipse即可

  5. win10下JDK安装,配置环境变量后报Error: could not open `C:\Program Files\Java\jre1.8.0_112\lib\amd64\jvm.cfg'

    把Path里面的%JAVA_HOME%/bin放在最前面.

  6. HDU 1221 Rectangle and Circle 考虑很多情况,good题

    http://acm.hdu.edu.cn/showproblem.php?pid=1221 114 92 31 95 13 96 3 这题只需要判断圆和矩形是否相交,然后在里面是不算相交的. 那么就 ...

  7. 组件的 state 和 setState

    state 我们前面提到过,一个组件的显示形态是可以由它数据状态和配置参数决定的.一个组件可以拥有自己的状态,就像一个点赞按钮,可以有“已点赞”和“未点赞”状态,并且可以在这两种状态之间进行切换.Re ...

  8. [BZOJ1045][HAOI2008]糖果传递 数学

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1045 我们假设每一个小朋友的代价为$x[i]$,每一次都从前面一个小朋友那里拿,这种贪心跟 ...

  9. Android单独继承View类来实现自定义控件

    一个单独继承view类来实现自定义控件,在该方法中,需要重写ondraw方法来绘制自己所需要的控件,下面也以一个简单的例子来说明如何实现自定义控件.该方法可以实现所需要的所有的自定义控件. 属性文件中 ...

  10. 离开APM的弹性云还是真弹性吗

    准确来说应该叫脱离业务的弹性云或者容器都是伪弹性.之所以标题中有APM一是因为它近来热门,二是因为它在我将要说的这个事情上起到关键性的作用. 不管是亚马逊的弹性云.容器方案或者国内众多云厂商在自动伸缩 ...