POJ 2553 The Bottom of a Graph(强连通分量的出度)
题意:
求出图中所有汇点
定义:点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(强连通分量的出度)的更多相关文章
- poj 2553 The Bottom of a Graph(强连通分量+缩点)
题目地址:http://poj.org/problem?id=2553 The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K ...
- POJ 2553 The Bottom of a Graph (强连通分量)
题目地址:POJ 2553 题目意思不好理解.题意是:G图中从v可达的全部点w,也都能够达到v,这种v称为sink.然后升序输出全部的sink. 对于一个强连通分量来说,全部的点都符合这一条件,可是假 ...
- 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 ...
- POJ 2553 The Bottom of a Graph(强连通分量)
POJ 2553 The Bottom of a Graph 题目链接 题意:给定一个有向图,求出度为0的强连通分量 思路:缩点搞就可以 代码: #include <cstdio> #in ...
- POJ-2552-The Bottom of a Graph 强连通分量
链接: https://vjudge.net/problem/POJ-2553 题意: We will use the following (standard) definitions from gr ...
- poj 2553 The Bottom of a Graph【强连通分量求汇点个数】
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9641 Accepted: ...
- [poj 2553]The Bottom of a Graph[Tarjan强连通分量]
题意: 求出度为0的强连通分量. 思路: 缩点 具体有两种实现: 1.遍历所有边, 边的两端点不在同一强连通分量的话, 将出发点所在强连通分量出度+1. #include <cstdio> ...
- POJ 2553 The Bottom of a Graph (Tarjan)
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11981 Accepted: ...
- POJ 2553 The Bottom of a Graph Tarjan找环缩点(题解解释输入)
Description We will use the following (standard) definitions from graph theory. Let V be a nonempty ...
随机推荐
- Spring + MyBaits java.lang.reflect.InvocationTargetException 启动日志报错
调试发现 实例化 class org.apache.ibatis.logging.slf4j.Slf4jImpl时发生异常,所以 slf4j jar 问题解决: http://www.cnblogs. ...
- Beautiful People SGU - 199 ZOJ - 2319
最长上升子序列O(n log n):http://www.cnblogs.com/hehe54321/p/cf-340d.html 题目:https://cn.vjudge.net/problem/Z ...
- Android Studio编译开源项目(含NDK开发)常见报错
1.未设置NDK的路径 Error:Execution failed for task ':library:ndkBuild'. > A problem occurred starting pr ...
- 构建微服务开发环境6————利用npm安装前端框架
[内容指引] 安装JQuery组件: 安装BootStrap前端框架; 安装AngularJs前端框架: 安装angular动画模块: 安装angular的ui-router模块. 一.进入下载的目标 ...
- vs 2017 下 千万不要装force utf8 这个插件
千万不要装!!! 装了之后,传文件到linux系统下,各种xml和makefile报错(如下) Makefile:1: *** 遗漏分隔符 . 停止
- html语法第 -2
1 <html> 2 <head> 3 <title>这是第一节课网页标题</title> 4 <meta charset="UTF-8 ...
- 使用MySQL统计页面访问及排名
统计访问页面数量,以分辨率进行排名 SELECT CONCAT(`height` , '*', `width`) AS `resolution` , COUNT(CONCAT(`height`, '* ...
- js单线程和js异步操作的几种方法
一.为什么JavaScript是单线程? JavaScript语言的一大特点就是单线程,也就是说,同一个时间只能做一件事. JavaScript的单线程,与它的用途有关.作为浏览器脚本语言,JavaS ...
- 开发笔记 - 解决font-awesome等图标在浏览器中的兼容问题
今天在写前端页面的时候,觉得font-awesome简单实用就上手试了一下,因为font-awesome图标库甚为强大,我就在其css上多做了一些尝试,这一尝试发现了一个致命的问题,当我对i标签进行统 ...
- 迅为iMX6UL Cortex-A7架构单核ARM开发板接口介绍-支持定制
支持商业级和工业级核心板 1. POWER 电源接口电源输入为 5V/2A+,给核心板提供 5V 电源,给底板供电.原理图部分如下图所示. 电源接口位置如下图所示. 2. SWITCH 电源开关轻触电 ...