POJ2553
题意:很难懂!但是大体意思就是求有向图中从一个节点出发到达的点也能反向到达该节点的点。如a能到{b1,b2.....bx}这些点,而这些点也能到a,则a为要求的点。题目是求出所有的这种点。
对图进行缩点,缩点后出度为0的点(强连通分量)所包含的点就是答案。原因,自己思考一下.....
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
const int maxn=;
const int maxm=;
int n,m;
struct edge
{
int u,v,next;
}e[maxm],ee[maxm];
int head[maxn],js,headd[maxn],jss;
int dfsn[maxn],low[maxn],visx,sshu;
int belong[maxn],ss[maxn];
stack<int>st;
bool ins[maxn];
int chudu[maxn];
vector<int>bl[maxn];
vector<int>ans;
void init()
{
memset(head,,sizeof(head));
memset(e,,sizeof(e));
js=;
memset(headd,,sizeof(headd));
memset(ee,,sizeof(ee));
jss=;
memset(dfsn,,sizeof(dfsn));
memset(low,,sizeof(low));
visx=sshu=;
memset(belong,,sizeof(belong));
memset(ss,,sizeof(ss));
while(!st.empty())st.pop();
memset(ins,,sizeof(ins));
memset(chudu,,sizeof(chudu));
ans.resize();
for(int i=;i<maxn;i++)bl[i].resize();
}
void addage(int u,int v,edge e[],int head[],int &js)
{
e[++js].u=u;e[js].v=v;
e[js].next=head[u];head[u]=js;
}
void tarjan(int u)
{
low[u]=dfsn[u]=++visx;
st.push(u);
ins[u]=;
for(int i=head[u];i;i=e[i].next)
{
int v=e[i].v;
if(dfsn[v]==)
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(ins[v] && low[u]>dfsn[v]) low[u]=dfsn[v];
}
if(low[u]==dfsn[u])
{
sshu++;
int tp;
do{
tp=st.top();
st.pop();
ins[tp]=;
bl[sshu].push_back(tp);
belong[tp]=sshu;
ss[sshu]++;
}while(tp!=u);
}
}
void addd(int x)
{
for(int i=;i<bl[x].size();i++)
{
int y=bl[x][i];
ans.push_back(y);
}
} int main()
{
while(scanf("%d%d",&n,&m)==)
{
init();
for(int u,v,i=;i<m;i++)
{
scanf("%d%d",&u,&v);
addage(u,v,e,head,js);
}
for(int i=;i<=n;i++)
if(dfsn[i]==)tarjan(i);
for(int i=;i<=m;i++)
{
int u=e[i].u,v=e[i].v;
if(belong[u]!=belong[v])
{
addage(belong[u],belong[v],ee,headd,jss);
chudu[belong[u]]++;
}
}
for(int i=;i<=sshu;i++)
if(chudu[i]==)addd(i);
sort(ans.begin(),ans.end());
for(int i=;i<ans.size();i++)printf("%d ",ans[i]);
printf("\n");
} return ;
}
POJ2553的更多相关文章
- poj2553 强连通缩点
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 10114 Accepted: ...
- POJ2553 The Bottom of a Graph(强连通分量+缩点)
题目是问,一个有向图有多少个点v满足∀w∈V:(v→w)⇒(w→v). 把图的强连通分量缩点,那么答案显然就是所有出度为0的点. 用Tarjan找强连通分量: #include<cstdio&g ...
- poj2553 强连通
题意:定义了一个图的底(bottom),是指在一个图中能够被所有点到达的点,问途中有哪些点是图的底. 首先是同一个强连通分量中的点都能够互相到达,强连通分量中一个点能到达其他点,也必然代表该强连通分量 ...
- 强连通分量+缩点(poj2553)
http://poj.org/problem?id=2553 The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total ...
- 【poj2553】The Bottom of a Graph(强连通分量缩点)
题目链接:http://poj.org/problem?id=2553 [题意] 给n个点m条边构成一幅图,求出所有的sink点并按顺序输出.sink点是指该点能到达的点反过来又能回到该点. [思路] ...
- POJ2553 汇点个数(强连通分量
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 12070 Accepted: ...
- POJ2553( 有向图缩点)
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9779 Accepted: ...
- poj2553 有向图缩点,强连通分量。
//求这样的sink点:它能达到的点,那个点必能达到他,即(G)={v∈V|任意w∈V:(v→w)推出(w→v)} //我法:tarjan缩点后,遍历点,如果该点到达的点不在同一个强连通中,该点排除, ...
- POJ2553 强连通出度为0的应用
题意: 给你一个有向图,然后问你有多少个满足要求的点,要求是: 这个点能走到的所有点都能走回这个点,找到所有的这样的点,然后排序输出. 思路: 可以直接一遍强连通缩点,所点之后 ...
随机推荐
- 【转】apache DateFormatUtils 与 DateUtils 的使用
在Apache Commons项目的Lang里面,有两个类:DateUtils和DateFormatUtils,专门用于处理时间日期转换.它们在 org.apache.commons.lang.tim ...
- Maven如何添加Oracle驱动包到本地仓库中
2016-05-28 http://note.youdao.com/yws/public/redirect/share?id=54cbe79c8948113ef492f946f7e027c8& ...
- 常用的.Net 知识点
1.Replace C#:(using System.Text.RegularExpressions;) string txt = Regex.Replace(txtLog.Text.ToString ...
- 7、IMS - DNS & ENUM
1.相关基础SBC:http://blog.sina.com.cn/s/blog_7a6f76080100vp9r.html 2.ENUM/DNS查询过程:http://blog.sina.com.c ...
- Android 软引用
2013-08-13 13:56 佚名 eoe Android开发者社区 字号:T | T 可能对于Android开发者来说,软引用这个词有的会不是很熟悉,软引用在Java开发中用的比较多,但是, ...
- Maven依赖版本冲突的分析及解决小结
1:前言 做软件开发这几年遇到了许多的问题,也总结了一些问题的解决之道,之后慢慢的再遇到的都是一些重复性的问题了,当然,还有一些自己没有完全弄明白的问题.如果做的事情是重复的,遇到重复性问题的概率也就 ...
- Sublime Text 3 使用
Sublime Text3使用 下载安装 参考:http://www.downza.cn/soft/187996.html Sublime Text Build 3126 x64 Setup.exe下 ...
- Android IOS WebRTC 音视频开发总结(八十七)-- WebRTC中丢包重传NACK实现分析
本文主要介绍WebRTC中丢包重传NACK的实现,作者:weizhenwei ,文章最早发表在编风网,微信ID:befoio 支持原创,转载必须注明出处,欢迎关注我的微信公众号blacker(微信ID ...
- ubuntu 'Unable to correct problems, you have held broken packages' 错误
在用apt 安装软件时,有时会用国内的源以加快下载速度. 但是在使用ubuntu 14.04的过程中,这一过程可能会导致错误“Unable to correct problems, you have ...
- python迭代器,生成器,装饰器,context模块
迭代器iteration 是访问集合元素的一种方式,只能往前不能往后迭代器的特点:1,访问者不需要关注迭代器内部结构,只需通过next()不断取下一个内容2,访问不能回退3,循环较大数据集合时,省内存 ...