题意:很难懂!但是大体意思就是求有向图中从一个节点出发到达的点也能反向到达该节点的点。如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的更多相关文章

  1. poj2553 强连通缩点

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10114   Accepted: ...

  2. POJ2553 The Bottom of a Graph(强连通分量+缩点)

    题目是问,一个有向图有多少个点v满足∀w∈V:(v→w)⇒(w→v). 把图的强连通分量缩点,那么答案显然就是所有出度为0的点. 用Tarjan找强连通分量: #include<cstdio&g ...

  3. poj2553 强连通

    题意:定义了一个图的底(bottom),是指在一个图中能够被所有点到达的点,问途中有哪些点是图的底. 首先是同一个强连通分量中的点都能够互相到达,强连通分量中一个点能到达其他点,也必然代表该强连通分量 ...

  4. 强连通分量+缩点(poj2553)

    http://poj.org/problem?id=2553 The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total ...

  5. 【poj2553】The Bottom of a Graph(强连通分量缩点)

    题目链接:http://poj.org/problem?id=2553 [题意] 给n个点m条边构成一幅图,求出所有的sink点并按顺序输出.sink点是指该点能到达的点反过来又能回到该点. [思路] ...

  6. POJ2553 汇点个数(强连通分量

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12070   Accepted: ...

  7. POJ2553( 有向图缩点)

    The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 9779   Accepted:  ...

  8. poj2553 有向图缩点,强连通分量。

    //求这样的sink点:它能达到的点,那个点必能达到他,即(G)={v∈V|任意w∈V:(v→w)推出(w→v)} //我法:tarjan缩点后,遍历点,如果该点到达的点不在同一个强连通中,该点排除, ...

  9. POJ2553 强连通出度为0的应用

    题意:       给你一个有向图,然后问你有多少个满足要求的点,要求是: 这个点能走到的所有点都能走回这个点,找到所有的这样的点,然后排序输出. 思路:       可以直接一遍强连通缩点,所点之后 ...

随机推荐

  1. RIO-SEIO水泵流量表

    http://rio-seio.com/TW/products_pumps/Rio_plus.html 流量表:

  2. Android 进程通信机制之 AIDL

    什么是 AIDL AIDL 全称 Android Interface Definition Language,即 安卓接口描述语言.听起来很深奥,其实它的本质就是生成进程间通信接口的辅助工具.它的存在 ...

  3. Flavors

    Flavors¶ Flavor interface. class novaclient.v1_1.flavors.Flavor(manager, info, loaded=False) Bases: ...

  4. HDP 2.3 Notes

    Hortonworks Data Platform 2.3.4.0-3485 [bug] /usr/hdp/2.3.4.0-3485/zookeeper/bin/zkEnv.sh 26 if [ -z ...

  5. storm 配置,呵呵。

    配置项 配置说明 storm.zookeeper.servers ZooKeeper服务器列表 storm.zookeeper.port ZooKeeper连接端口 storm.local.dir s ...

  6. tomcat8和7关于自定义tag的处理区别

    今天将一直运行在tomcat-7.0.29(jdk1.6)上的应用迁移到tomcat-8.0.26(jdk1.7)上面,老显示如下错误: org.apache.jasper.JasperExcepti ...

  7. load mainaccount

    static void LoadMainAccountCSV(Args _args) { /* SysExcelApplication        excel; SysExcelWorkbooks  ...

  8. Do things for others

    早上,按照平常的时间去吃早饭,食堂格外的空旷,打饭的员工说今天人很少,我说昨天是有元旦晚会,她说今天是放假,我后来想,还是她说的更有道理.她看的比我清楚更清楚! 幸亏昨晚上记录下了早上要帮别人搜论文的 ...

  9. web开发过程中经常用到的一些公共方法及操作

    进化成为程序猿也有段岁月了,所谓的经验,广度还是依旧,只不过是对于某种功能有了多种实现方式的想法.每天依旧不厌其烦的敲打着代码,每一行代码的回车似乎都有一种似曾相识的感觉.于是乎:粘贴复制,再粘贴再复 ...

  10. Javascript中的Promise

    Promise定义 Promise是CommonJs的规范之一,包含resolve,reject,done,fail,then等方法,能够帮助我们控制代码的流程,避免函数的多层嵌套.异步在web开发中 ...