poj 2553 The Bottom of a Graph 强连通缩点
来源:互联网 发布:c语言病毒吃内存 编辑:程序博客网 时间:2024/06/05 23:14
题意:
如果一个点v能够到达w,反过来w也能到达v点,那么称v点为sink点(汇点)。求出给定图中所有sink点,并按序号递增的顺序输出。
思路
在一个连通分量中,任意两点总是能够相互到达,将强连通分量缩点后,得到的dag中,求出出度为0的点就是答案。
#include<cstdio>#include<queue>#include<iostream>#include<vector>#include<map>#include<cstring>#include<string>#include<set>#include<stack>#include<algorithm>#define cle(a) memset(a,0,sizeof(a))#define inf(a) memset(a,0x3f,sizeof(a))#define ll long long#define Rep(i,a,n) for(int i=a;i<=n;i++)using namespace std;const int INF = ( 2e9 ) + 2;const ll maxn = 5e3+10;vector<int> g[maxn];int dfn[maxn],low[maxn],instack[maxn],scc[maxn],Out[maxn];int time,num;stack<int> s;void tarjan(int u){ dfn[u]=low[u]=++time; s.push(u); instack[u]=1; for(int i=0;i<g[u].size();i++) { int v=g[u][i]; if(!dfn[v]) { tarjan(v); low[u]=min(low[u],low[v]); } else if(instack[v]) low[u]=min(low[u],low[v]); } if(low[u]==dfn[u]) { num++; int x; do { x=s.top();s.pop(); instack[x]=0; scc[x]=num; }while(x!=u); }}int main(){ int n,m; while(scanf("%d",&n)&&n) { scanf("%d",&m); time=num=0; while(!s.empty())s.pop(); memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(Out,0,sizeof(Out)); for(int i=1;i<=n;i++)g[i].clear(); for(int i=0;i<m;i++) { int u,v; scanf("%d%d",&u,&v); g[u].push_back(v); } for(int i=1;i<=n;i++) if(!dfn[i])tarjan(i); for(int u=1;u<=n;u++) for(int i=0;i<g[u].size();i++) { if(scc[u]!=scc[g[u][i]]) { Out[scc[u]]++; } } int fir=1; for(int i=1;i<=n;i++) if(Out[scc[i]]==0) { if(fir) { printf("%d",i); fir=0; } else printf(" %d",i); } printf("\n"); }}
阅读全文
0 0
- poj 2553 The Bottom of a Graph 强连通缩点
- poj 2553 The Bottom of a Graph(强连通分量)
- [强连通]poj 2553 The Bottom of a Graph
- POJ 2553 The Bottom of a Graph 强联通分量
- POJ 2553 The Bottom of a Graph 强连通分量
- POJ 2553 The Bottom of a Graph 强连通
- POJ 2553 The Bottom of a Graph(强连通分量)
- poj 2553 The Bottom of a Graph(强连通)
- POJ 2553 The Bottom of a Graph (强连通分量)
- poj 2553 The Bottom of a Graph 强连通Kosaraju
- POJ 2553:The Bottom of a Graph【强连通】
- POJ 2553 The Bottom of a Graph(强连通分量)
- POJ 2553 The Bottom of a Graph 强连通分量
- poj 2553 The Bottom of a Graph【强连通分量】
- POJ 2553 The Bottom of a Graph 强连通分量+缩点 tarjan or kosaraju
- poj 2553 The Bottom of a Graph 【强连通图中出度为0点】
- poj 2553 The Bottom of a Graph (强联通分量+缩点)
- 【连通图|强连通+缩点】POJ-2553 The Bottom of a Graph
- 【《Real-Time Rendering 3rd》 提炼总结】(四) 第五章 · 图形渲染与视觉外观 The Visual Appearance
- ftp上传和下载
- 如何正确使用Git Flow
- QT功能1:点击按钮,显示图片
- 【理论实践】快速认识allocator,并不神奇但吓退一片的内存管理机制:内存分配和对象构造分离
- poj 2553 The Bottom of a Graph 强连通缩点
- 记录一 MVC框架
- replaceAll小心使用
- 【《Real-Time Rendering 3rd》 提炼总结】(三) 第三章 · GPU渲染管线与可编程着色器 The Graphics Processing Unit
- UESTC
- 2017年8月17日训练日记
- python第三方包安装错误:Unable to find vcvarsall.bat
- hadoop生态圈列式存储系统--kudu介绍及安装配置
- 【《Real-Time Rendering 3rd》 提炼总结】(二) 第二章 · 图形渲染管线 The Graphics Rendering Pipeline