id=2553">主题链接

题意:求解Bottom(G)。即集合内的点能够互相到达。

思路:有向图的强连通。缩点,找出出度为0的点,注意符合的点要按升序输出。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAXN = 5010;
const int MAXM = 50010; struct Edge{
int to, next;
}edge[MAXM]; int head[MAXN], tot;
int Low[MAXN], DFN[MAXN], Stack[MAXN], Belong[MAXN];
int Index, top;
int scc;
bool Instack[MAXN];
int num[MAXN];
int n, m;
int out[MAXN], ans[MAXN]; void init() {
tot = 0;
memset(head, -1, sizeof(head));
} void addedge(int u, int v) {
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u) {
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
for (int i = head[u]; i != -1; i = edge[i].next) {
v = edge[i].to;
if (!DFN[v]) {
Tarjan(v);
if (Low[u] > Low[v]) Low[u] = Low[v];
}
else if (Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if (Low[u] == DFN[u]) {
scc++;
do {
v = Stack[--top];
Instack[v] = false;
Belong[v] = scc;
num[scc]++;
} while (v != u);
}
} void solve() {
memset(Low, 0, sizeof(Low));
memset(DFN, 0, sizeof(DFN));
memset(num, 0, sizeof(num));
memset(Stack, 0, sizeof(Stack));
memset(Instack, false, sizeof(Instack));
Index = scc = top = 0;
for (int i = 1; i <= n; i++)
if (!DFN[i])
Tarjan(i);
} int main() {
while (scanf("%d%d", &n, &m) && n) {
init();
int u, v;
for (int i = 0; i < m; i++) {
scanf("%d%d", &u, &v);
addedge(u, v);
}
solve(); memset(out, 0, sizeof(out));
for (int u = 1; u <= n; u++) {
for (int i = head[u]; i != -1; i = edge[i].next) {
int v = edge[i].to;
if (Belong[u] != Belong[v])
out[Belong[u]]++;
}
}
memset(ans, 0, sizeof(ans));
int cnt = 0;
for (int i = 1; i <= scc; i++)
for (int u = 1; u <= n; u++) {
if (out[i] == 0) {
if (Belong[u] == i)
ans[cnt++] = u;
}
}
sort(ans, ans + cnt);
for (int i = 0; i < cnt; i++)
if (i == 0) printf("%d", ans[i]);
else printf(" %d", ans[i]);
printf("\n");
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

POJ2553-The Bottom of a Graph的更多相关文章

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

    题目是问,一个有向图有多少个点v满足∀w∈V:(v→w)⇒(w→v). 把图的强连通分量缩点,那么答案显然就是所有出度为0的点. 用Tarjan找强连通分量: #include<cstdio&g ...

  2. 【图论】The Bottom of a Graph

    [POJ2553]The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 11182   ...

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

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

  4. The Bottom of a Graph(tarjan + 缩点)

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

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

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

  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)

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

  8. The Bottom of a Graph

                                    poj——The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K ...

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

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

  10. poj--2553--The Bottom of a Graph (scc+缩点)

    The Bottom of a Graph Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Oth ...

随机推荐

  1. __declspec(dllimport)的作用

    是时候总结一下__declspec(dllimport)的作用了.可能有人会问:__declspec(dllimport)和__declspec(dllexport)是一对的,在动态链接库中__dec ...

  2. uva156 By sixleaves

    1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 #include <ma ...

  3. linux监控脚本,脚本支持传参,整合C程序

    1,查看指定用户下的进程pid

  4. Linux,Unix各种版本的操作系统在线安装软件命令

    摘自:http://blog.csdn.net/zjg555543/article/details/8278266 linux和unix,各个版本的操作系统都有自己的软件安装方式,最方便的莫过于在线安 ...

  5. CentoS6.x网络配置

    一.配置文件 在CentoS系统里面,跟网络有关的主要配置文件有    1./etc/host.conf # 配置域名服务客户端的控制文件 2./etc/hosts # 配置主机名映射为IP的功能 3 ...

  6. Oracle SecureFiles 说明(转)

    Oracle SecureFiles 说明 Oracle Database 11g 将LOB 数据类型作为Oracle SecureFiles 进行了完全重新设计,显著改进了应用程序开发的性能.可管理 ...

  7. js简易写法

    我写JavaScript代码已经很久了,都记不起是什么年代开始的了.对于JavaScript这种语言近几年所取得的成就,我感到非常的兴奋:我很幸运也是这些成就的获益者.我写了不少的文章,章节,还有一本 ...

  8. 根据Model有值的自动生成添加的Sql语句

    static string Table_Name = ""; /// <summary> /// model实体中的字段名相对数据库表添加的字段 /// 如: /// ...

  9. .Net 缓存依赖详解

    缓存命名空间的讲解流程 16.1  System.Web.Caching简介 本节从缓存命名空间的总体简介和组成结构入手,从整体上对System.Web.Caching进行概述. 16.1.1  Sy ...

  10. Oracle的分页查询语句优化

    Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. (一)   分页查询格式: SELECT * FROM  ( SELECT A.*, ROWNUM RN  FROM (SELECT ...