边的双连通分量问题
来源:互联网 发布:表格中数据怎么求和 编辑:程序博客网 时间:2024/05/17 02:10
连通性二·边的双连通分量
题目传送:hihoCoder - 1184 - 连通性二·边的双连通分量
AC代码:
#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <complex>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <utility>#include <iostream>#include <algorithm>#include <functional>#define LL long long#define INF 0x7fffffffusing namespace std;const int maxn = 20005;int n, m;vector<int> G[maxn];stack<int> s;int vis[maxn];int low[maxn];int dfn[maxn];int ans[maxn];int cur_time, cnt;void dfs(int u, int fa) { low[u] = dfn[u] = ++ cur_time; vis[u] = 1; s.push(u); int d = G[u].size(); for(int i = 0; i < d; i ++) { int v = G[u][i]; if(!vis[v]) { dfs(v, u); low[u] = min(low[u], low[v]); } else if(v != fa){ low[u] = min(low[u], dfn[v]); } } if(low[u] == dfn[u]) { cnt ++; stack<int> ss; int MIN = INF; while(s.top() != u) { MIN = min(MIN, s.top()); ss.push(s.top()); s.pop(); } MIN = min(MIN, s.top()); ss.push(s.top()); s.pop(); while(!ss.empty()) { ans[ss.top()] = MIN; ss.pop(); } }}int main() { scanf("%d %d", &n, &m); int u, v; for(int i = 0; i < m; i ++) { scanf("%d %d", &u, &v); G[u].push_back(v); G[v].push_back(u); } while(!s.empty()) s.pop(); cur_time = cnt = 0; memset(vis, 0, sizeof(vis)); dfs(1, -1); printf("%d\n", cnt); for(int i = 1; i < n; i ++) { printf("%d ", ans[i]); } printf("%d\n", ans[n]); return 0;}
0 0
- 边的双连通分量问题
- 点的双连通分量问题
- 边双连通分量
- POJ 3352 边的双连通分量
- 双连通分量的求解
- 点-双连通分量&边-双连通分量复习笔记
- 边双连通分量模版
- HDU4738【边双连通分量】
- 边双连通分量模板
- POJ 3177 Redundant Paths 边的双连通分量
- 无向图的边双连通分量
- hiho一下 连通性二·边的双连通分量
- tarjan算法(边的双连通分量)
- 求无向图的 边-双连通分量
- hihocoder 1184 : 连通性二·边的双连通分量
- hihocoder #1184 : 连通性二·边的双连通分量
- hiho 53 连通性二·边的双连通分量
- HIHO #1184 : 连通性二·边的双连通分量
- git使用
- Matlab自动控制系统应用
- Mars老师的Android学习路线。
- Linux ip命令详解
- Algorithms—235.Lowest Common Ancestor of a Binary Search Tree
- 边的双连通分量问题
- Reverse Integer
- 各种数据库相关
- Android SurfaceView实战 带你玩转flabby bird (下)
- python-动态特性学习
- Mac的可执行脚本,类似于windows批处理脚本
- hive中map和reduce优化
- 页面之间传值
- 动静态库及动静态链接