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的顶点 ...
随机推荐
- Lvs+heartbeat高可用高性能web站点的搭建
这是我们公司在实际的生产环境当中使用的一套东西,希望对大家有所帮助(实际的公网ip,我已经做了相应的修改): 说明:每台服务器需要有两块网卡:eth0连接内网的交换机,用私网ip,实现服务器间内部访问 ...
- STM32 的 printf() 函数串口重定向(HAL库标准库都适用)
1.建立工程 2.核心:添加新文件usar_fputc.c (名字随便自己命名),把文件添加到项目中去 #include "stdio.h" #include "stm3 ...
- [terry笔记]python内置函数
总结一下内置函数,Build-in Function. 一.数学运算类 abs(x) 求绝对值 complex([real[, imag]]) 创建一个复数 divmod(a, b) 分别取商和余数注 ...
- Jquery-select元素操作方法
jQuery获取Select元素,并选择的Text和Value: $("#select_id").change(function(){//code...}); //为Select添 ...
- 远古守卫/cocos2d-x 源代码/塔防游戏/高仿王国保卫战
下载地址:spm=686.1000925.0.0.j3MZhz&id=550780702354" style="color:rgb(224,102,102)"&g ...
- Android自己定义矩形及selector、shape的使用
[声明]转载请注明出处.此文出自指尖飞落的博客:http://blog.csdn.net/huntersnail --每天写一篇博客.每天做一点技术积累! Android自己定义矩形及selector ...
- Linux 设备文件的创建和mdev
引子 本文是嵌入式企鹅圈开篇--<linux字符设备驱动剖析>的姐妹篇,在上述文章里面我们具体描写叙述了字符设备驱动框架涉及的驱动注冊.通过设备文件来訪问驱动等知识.并明白通过device ...
- 发送HTTP请求 -- HttpUtil
1. package com.step.utils; import java.io.IOException; import java.net.URLDecoder; import java.util. ...
- ASP.NET MVC5 历史数据查询
在TCX_1706项目中在历史数据库备份及历史数据查询的功能,历史数据包括历史采集数据查询和历史产品数据查询两个 在项目中如何查询历史库的历史表呢? 第一步:在配置文件中添加历史库的链接字符串 第二步 ...
- 关于jsp web项目,jsp页面与servlet数据不同步的解决办法(报错404、405等)即访问.jsp和访问web.xml中注册的/servlet/的区别
报错信息: Type Status Report Message HTTP method GET is not supported by this URL Description The method ...