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的应用
题意: 给你一个有向图,然后问你有多少个满足要求的点,要求是: 这个点能走到的所有点都能走回这个点,找到所有的这样的点,然后排序输出. 思路: 可以直接一遍强连通缩点,所点之后 ...
随机推荐
- StackPanel在增加控件的问题
今天遇到这样一个问题,就是我做了一个自定义控件.然后加到StackPanel中, <StackPanel Height="676" HorizontalAlignment=& ...
- system verilog中的类型转换(type casting)、位宽转换(size casting)和符号转换(sign casting)
类型转换 verilog中,任何类型的任何数值都用来给任何类型赋值.verilog使用赋值语句自动将一种类型的数值转换为另一种类型. 例如,当一个wire类型赋值给一个reg类型的变量时,wire类型 ...
- 通过Spark SQL关联查询两个HDFS上的文件操作
order_created.txt 订单编号 订单创建时间 -- :: -- :: -- :: -- :: -- :: order_picked.txt 订单编号 订单提取时间 -- :: ...
- Arch Linux LibreOffice 中文输入法不能切换
From: http://blog.csdn.net/shallowgrave/article/details/8501629 卸载libreoffice-kde4 # pacman -R libre ...
- tomcat源码剖析
最近看Tomcat的源码的节奏还算是挺紧凑的,给人的感觉,tomcat的代码相对以前读的jetty的代码显得更有条理一些...当然这也是有可能是因为自己看的jetty的版本是比较老的,而看的Tomca ...
- 配置web项目时页面报错java.lang.NoClassDefFoundError: Tag
把tomcat:common\lib 下的servlet-api.jar 和jsp-api.jar cp到项目的web-inf 的lib包里 ,重启项目即可
- H5新出的flex布局
百度前端技术学院第一阶段中的任务十,就是关于flexbox布局的 与flexbox布局相关的资料如下: 1.flex布局教程-语法篇-阮一峰的网络日志 http://www.ruanyifeng.c ...
- UEditor使用说明
页面加入ue<!-- umeditor --><script type="text/javascript" charset="utf-8" s ...
- 重置zend studio 默认设置的方法
转载自:http://www.zendstudio.net/archives/reset-the-zend-studio-settings/ 这个方法类似于手机的"恢复出厂设置"的 ...
- 关于html自闭合标签要不要加空格和斜杠的问题?
问题描述:可能很多人都遇到过这个问题,写网页时,link img br input等等这些标签时到底要不要在结尾加上空格和斜杠呢? 我曾经貌似在<编写高质量代码>上看到过这样的介绍,遇到l ...