链接:

https://vjudge.net/problem/POJ-2553

题意:

We will use the following (standard) definitions from graph theory. Let V be a nonempty and finite set, its elements being called vertices (or nodes). Let E be a subset of the Cartesian product V×V, its elements being called edges. Then G=(V,E) is called a directed graph.

Let n be a positive integer, and let p=(e1,...,en) be a sequence of length n of edges ei∈E such that ei=(vi,vi+1) for a sequence of vertices (v1,...,vn+1). Then p is called a path from vertex v1 to vertex vn+1 in G and we say that vn+1 is reachable from v1, writing (v1→vn+1).

Here are some new definitions. A node v in a graph G=(V,E) is called a sink, if for every node w in G that is reachable from v, v is also reachable from w. The bottom of a graph is the subset of all nodes that are sinks, i.e., bottom(G)={v∈V|∀w∈V:(v→w)⇒(w→v)}. You have to calculate the bottom of certain graphs.

求哪些点能到的点都可以到自己

思路:

一个强连通分量内的点互相可达,所有一个强连通分量没有出度,则这个强连通内的点都满足条件。

代码:

#include <iostream>
#include <cstdio>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
using namespace std;
const int MAXN = 5e3+10; vector<int> G[MAXN];
stack<int> St;
int Dfn[MAXN], Low[MAXN];
int Dis[MAXN], Vis[MAXN];
int Fa[MAXN];
int times, cnt;
int n, m; void Tarjan(int x)
{
Dfn[x] = Low[x] = ++times;
St.push(x);
Vis[x] = 1;
for (int i = 0;i < G[x].size();i++)
{
int nextnode = G[x][i];
if (Dfn[nextnode] == 0)
{
Tarjan(nextnode);
Low[x] = min(Low[x], Low[nextnode]);
}
else if (Vis[nextnode])
Low[x] = min(Low[x], Dfn[nextnode]);
}
if (Low[x] == Dfn[x])
{
cnt++;
while (St.top() != x)
{
Fa[St.top()] = cnt;
Vis[St.top()] = 0;
St.pop();
}
Fa[St.top()] = cnt;
Vis[St.top()] = 0;
St.pop();
}
} void Init()
{
memset(Dis, 0, sizeof(Dis));
memset(Vis, 0, sizeof(Vis));
memset(Dfn, 0, sizeof(Dfn));
for (int i = 1;i <= n;i++)
G[i].clear(), Fa[i] = i;
times = cnt = 0;
while (!St.empty())
St.pop();
} int main()
{
while (~scanf("%d", &n) && n)
{
Init();
scanf("%d", &m);
int l, r;
for (int i = 1;i <= m;i++)
{
scanf("%d%d", &l, &r);
G[l].push_back(r);
}
for (int i = 1;i <= n;i++)
if (Dfn[i] == 0)
Tarjan(i);
for (int i = 1;i <= n;i++)
{
for (int j = 0;j < G[i].size();j++)
{
int node = G[i][j];
if (Fa[i] != Fa[node])
Dis[Fa[i]]++;
}
}
int flag = 0;
for(int i=1;i<=n;i++)
{
if (Dis[Fa[i]] == 0)
{
if (!flag)
{
printf("%d", i);
flag = 1;
}
else printf(" %d", i);
}
}
printf("\n");
} return 0;
}

POJ-2552-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. 【poj2553】The Bottom of a Graph(强连通分量缩点)

    题目链接:http://poj.org/problem?id=2553 [题意] 给n个点m条边构成一幅图,求出所有的sink点并按顺序输出.sink点是指该点能到达的点反过来又能回到该点. [思路] ...

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

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

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

  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(强连通分量的出度)

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

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

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

随机推荐

  1. Kotlin 的 @JvmStatic 和 @JvmField 注解

    这是关于 Java 静态方法和静态变量的一段代码: public class TestStatic { private int otherField = 0; public static final ...

  2. java:Hibernate框架2(关联映射(多对一,一对多,一对多双向,一对一主键,一对一唯一外键,多对多双向))

      hibernate.cfg.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE h ...

  3. spring ehcache 缓存框架

    一.简介 Ehcache是一个用Java实现的使用简单,高速,实现线程安全的缓存管理类库,ehcache提供了用内存,磁盘文件存储,以及分布式存储方式等多种灵活的cache管理方案.同时ehcache ...

  4. 吴恩达机器学习(四) 使用Octave

    一.基本操作 本课程有编程作业,编程作业需要使用Matlab或Octave,本文章使用Octave.下载地址:http://www.gnu.org/software/octave/#install.安 ...

  5. vue-cli 3 ----- 项目频繁发送‘sockjs-node/info’请求

    在vue-cli3跑项目时发现了这个问题,浏览器一直在频繁发送这个请求,导致联调时很不方便,而且本地开发时项目也不能实时更新. 看了网上很多的 (1)  解决方案, 大多都是直接去node_modul ...

  6. xmake从入门到精通9:交叉编译详解

    xmake是一个基于Lua的轻量级现代化c/c 的项目构建工具,主要特点是:语法简单易上手,提供更加可读的项目维护,实现跨平台行为一致的构建体验. 除了win, linux, macOS平台,以及an ...

  7. 【Linux 网络编程】MTU(Maximum Transmission Uint)

    (1)以太网和IEEE802.3对数据帧的长度都是有限制的,其最大分别是1500和1492字节,成为MTU. (2)如果IP层有一个数据要传输,而且数据的长度比链路层的MTU要大,那么IP层就要进行分 ...

  8. spring boot-7.日志系统

    日志系统分为两部分,一部分是日志抽象层,一部分是日志实现层.常见的日志抽象层JCL,SLF4J,JBoss-Logging,日志实现层有logback,log4j,log4j2,JUL.日志抽象层的功 ...

  9. (5.2.2)配置服务器参数——dbcc跟踪标记(trace)

    关键字:跟踪标记,跟踪 [1]常规dbcc命令 dbcc help('?') --查看dbcc 所有命令,常规下只有32个常用的dbcc TRACEON(2588) --指定了2588标记的话,你就可 ...

  10. 如何实现Java线程的 阻塞/唤醒(和暂停/继续 类似)

    以下为线程 阻塞/唤醒  主要代码 public class MyThread extends Thread { //无意义 private final Object lock = new Objec ...