POJ——T2553 The Bottom of a Graph
http://poj.org/problem?id=2553
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 10987 | Accepted: 4516 |
Description
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+1is 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.
Input
Output

Sample Input
3 3
1 3 2 3 3 1
2 1
1 2
0
Sample Output
1 3
2
Source

#include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int MAXN();
const int N();
int n,m,u,v;
int sumedge,head[N];
struct Edge
{
int to,next;
Edge(int to=,int next=) :
to(to),next(next) {}
}edge[MAXN]; void ins(int from,int to)
{
edge[++sumedge]=Edge(to,head[from]);
head[from]=sumedge;
} int low[N],dfn[N],tim;
int Stack[N],instack[N],top;
int sumcol,col[N],point[N]; void DFS(int now)
{
low[now]=dfn[now]=++tim;
Stack[++top]=now; instack[now]=true;
for(int i=head[now];i;i=edge[i].next)
{
int go=edge[i].to;
if(!dfn[go])
DFS(go),low[now]=min(low[now],low[go]);
else if(instack[go]) low[now]=min(low[now],dfn[go]);
}
if(low[now]==dfn[now])
{
col[now]=++sumcol;
for(;Stack[top]!=now;top--)
{
col[Stack[top]]=sumcol;
instack[Stack[top]]=false;
}
instack[now]=false; top--;
}
} int cnt,ans[N],chudu[N]; void init()
{
tim=top=cnt=;
sumcol=sumedge=;
memset(ans,,sizeof(ans));
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(col,,sizeof(col));
memset(head,,sizeof(head));
memset(chudu,,sizeof(chudu));
memset(Stack,,sizeof(Stack));
memset(instack,,sizeof(instack));
} int main()
{
/*freopen("made.txt","r",stdin);
freopen("myout.txt","w",stdout);*/ while(~scanf("%d",&n)&&n)
{
scanf("%d",&m); init();
for(;m;m--)
scanf("%d%d",&u,&v),ins(u,v);
for(int i=;i<=n;i++)
if(!dfn[i]) DFS(i);
for(u=;u<=n;u++)
for(v=head[u];v;v=edge[v].next)
if(col[u]!=col[edge[v].to]) chudu[col[u]]++;
/*for(int sc=1;sc<=sumcol;sc++)
if(!chudu[sc])
for(int i=1;i<=n;i++)
if(sc==col[i]) ans[++cnt]=i;*/
for(int i=;i<=n;i++)
if(!chudu[col[i]]) ans[++cnt]=i;
sort(ans+,ans+cnt+);
if(cnt)
{
for(int i=;i<cnt;i++) printf("%d ",ans[i]);
printf("%d\n",ans[cnt]);
}
else printf("\n");
}
return ;
}
POJ——T2553 The Bottom of a Graph的更多相关文章
- POJ 2553 The Bottom of a Graph(强连通分量)
POJ 2553 The Bottom of a Graph 题目链接 题意:给定一个有向图,求出度为0的强连通分量 思路:缩点搞就可以 代码: #include <cstdio> #in ...
- 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 (Tarjan)
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 11981 Accepted: ...
- 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找环缩点(题解解释输入)
Description We will use the following (standard) definitions from graph theory. Let V be a nonempty ...
- poj 2553 The Bottom of a Graph : tarjan O(n) 存环中的点
/** problem: http://poj.org/problem?id=2553 将所有出度为0环中的点排序输出即可. **/ #include<stdio.h> #include& ...
- 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
求解的是有向图中满足“自己可达的顶点都能到达自己”的顶点个数如果强连通分量中某个顶点,还能到达分量外的顶点,则该连通分量不满足要求// 因此,本题要求的是将强连通分量缩点后所构造的新图中出度为0的顶点 ...
随机推荐
- 常用js方法封装
常用js方法封装 var myJs = { /* * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值是格式化的字符串日期 */ getDates: fun ...
- RabbitMQ学习总结(6)——消息的路由分发机制详解
一.Routing(路由) (using the Java client) 在前面的学习中,构建了一个简单的日志记录系统,能够广播所有的日志给多个接收者,在该部分学习中,将添加一个新的特点,就是可以只 ...
- C++模板中的静态
#include <iostream> #include <stdlib.h> using namespace std; template<class T> cla ...
- (三 )kafka-jstorm集群实时日志分析 之 ---------jstorm集成spring 续(代码)
本地模式启动的. package com.doctor.kafkajstrom; import java.util.HashMap; import java.util.Map; import java ...
- POJ 1496 POJ 1850 组合计数
Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...
- 公布自己的pods到CocoaPods trunk 及问题记录
这两天准备把之前写的一些小玩意加入到pods库中去,參考了一些资料后进行操作,实际中也遇到了一些问题,记录下来.问题及解决方案在后面. 參考内容转载例如以下: 首先更新了用trunk之后,CocoaP ...
- bzoj1066: [SCOI2007]蜥蜴(最大流)
1066: [SCOI2007]蜥蜴 题目:传送门 题解: 哇QTT大佬一眼秒算法...ORT 其实很容易就可以看出来是一道最大流 因为有边的使用限制,那么就可以直接当成是流量来处理嘛 因为是对点进行 ...
- 把一串数字表示成千位分隔形式——toLocaleString()
听说你用什么正则?我这有个骚操作了解下.. toLocaleString() 方法可把一个 Number 对象转换为本地格式的字符串. ().toLocaleString('en-US') " ...
- BZOJ 4568 倍增维护线性基
在树的路径上选取一些点 使得这些点权xor后的结果最大 思路: 时限60s 59696ms卡过去了哈哈哈 //By SiriusRen #include <cstdio> #include ...
- POJ 1944 并查集(模拟)
思路: 肯定是要枚举断点的..就看枚举完断点以后怎么处理了-- 1.用类似并查集的思想- f[x]=max(f[x],y)表示x和y相连(一定要注意取max,,,血的教训) 复杂度O(np) 2.猥琐 ...