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. Mysql explain 查看分区表

    mysql> explain select * from ClientActionTrack where startTime>'2016-08-25 00:00:00' and start ...

  2. logstash 处理nginx 访问日志

    [root@dr-mysql01 frontend]# cat logstash_frontend.conf input { file { type => "zj_frontend_a ...

  3. C++的四种cast操作符的区别--类型转换

    Q:什么是C风格转换?什么是static_cast, dynamic_cast 以及 reinterpret_cast?区别是什么?为什么要注意? A:转换的含义是通过改变一个变量的类型为别的类型从而 ...

  4. Scrapy URLError

    错误信息如下: 2015-12-03 16:05:08 [scrapy] INFO: Scrapy 1.0.3 started (bot: LabelCrawler) 2015-12-03 16:05 ...

  5. Storages and virtual servers

    1. IBM Storages: SONAS,V7k,V7ku,SVC,XIV 存储设备都安装了个性化定制的Linux系统,来完成不同的服务,这几台存储设备使用原理都是类似的,以SONAS (Scal ...

  6. 依赖注入及AOP简述(九)——单例和无状态Scope .

    三.依赖注入对象的Scope及其生命周期 在前面的章节我们讲到,依赖注入容器之所以能够区别于以往的ServiceLocator等容器,是在于其不但能够自动构建多层次的.完整的依赖关系图,并且可以管理依 ...

  7. plaidctf2015 uncorrupt png

    代码的执行时间挺长的,好囧! 参考了https://13c5.wordpress.com/2015/04/20/plaidctf-2015-png-uncorrupt/的代码 通过这个题目,也对Png ...

  8. c++单元测试框架googletest

    一.概述 Googletest是一个用来写C++单元测试的框架,它是跨平台的,可应用在windows.linux.Mac等OS平台上: 代码框架: [root@docker googletest-re ...

  9. (转)MarginTop 为何影响父元素的 MarginTop

    这个问题困惑了很久,虽然没有大碍早就摸出来怎么搞定它,但始终不明白原因出在哪里,如果只是IE有问题我也不会太在意,可问题是所有上等浏览器都表现如此,这样叫我怎能安心?今天总算下狠心查出来怎么回事,居然 ...

  10. SQLServer 2012 已成功与服务器建立连接,但是在登录前的握手期间发生错误。 (provider: SSL Provider, error: 0 - 等待的操作过时。

    楼主用SQL Server 2012 在连接其他电脑的实例时,一直提示“已成功与服务器建立连接,但是在登录前的握手期间发生错误. (provider: SSL Provider, error: 0 - ...