poj 3177 Redundant Paths(Tarjan,边双连通分量)
来源:互联网 发布:网络盒子加密软件 编辑:程序博客网 时间:2024/06/05 08:23
kuangbin模板中的例题,我把模板里的InStack去掉了。
思路:
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int MAXN = 5010;const int MAXM = 20010;struct Edge{ int to,next; bool cut;} edge[MAXM];int head[MAXN],tot;int Low[MAXN],Dfn[MAXN],Stack[MAXN],Belong[MAXN];int Index,top;int block;int bridge;void addedge(int u, int v){ edge[tot].to = v; edge[tot].next = head[u]; edge[tot].cut = false; head[u] = tot++;}void init(){ memset(head,-1,sizeof(head)); tot = 0;}void Tarjan(int u, int pre){ int v; Low[u] = Dfn[u] = ++Index; Stack[top++] = u; for(int i = head[u]; i != -1; i = edge[i].next) { v = edge[i].to; if(v == pre) continue; if(!Dfn[v]) { Tarjan(v,u); if(Low[u] > Low[v]) Low[u] = Low[v]; if(Low[v] > Dfn[u]) { bridge++; edge[i].cut = true; edge[i^1].cut = true; } } else if(Low[u] > Dfn[v]) Low[u] = Dfn[v]; } if(Low[u] == Dfn[u]) { block++; do { v = Stack[--top]; Belong[v] = block; }while(v != u); }}int du[MAXN];void solve(int n){ memset(Dfn,0,sizeof(Dfn)); Index = top = block = 0; Tarjan(1,0); int ans = 0; memset(du,0,sizeof(du)); for(int i = 1; i <= n; ++i) { for(int j = head[i]; j != -1; j = edge[j].next) { if(edge[j].cut) du[Belong[i]]++; } } for(int i = 1; i <= block; ++i) if(du[i] == 1) ++ans; printf("%d\n",(ans+1)/2);}int main(){ int n,m,u,v; while(scanf("%d %d",&n,&m) != EOF) { init(); while(m--) { scanf("%d %d",&u,&v); addedge(u,v); addedge(v,u); } solve(n); } return 0;}
阅读全文
0 0
- POJ-3177 Redundant Paths (边双连通分量[Tarjan])
- poj 3177 Redundant Paths(Tarjan,边双连通分量)
- POJ 3177 Redundant Paths(边双连通分量+tarjan)
- poj 3177 Redundant Paths(双连通分量)
- 【POJ 3177】Redundant Paths(Tarjan求桥、边双连通分量)
- POJ 3177 Redundant Paths 边的双连通分量
- [边双连通分量] poj 3177 Redundant Paths
- POJ 3177 Redundant Paths(边双连通分量,3级)
- POJ 3177 Redundant Paths / 边双连通分量
- POJ 3177 Redundant Paths(边双连通分量+缩点)
- poj 3177 Redundant Paths 边双连通分量+缩点
- poj 3177 Redundant Paths 边双连通分量
- POJ 3177 Redundant Paths 边双连通分量+缩点
- POJ 3177 Redundant Paths(边双连通分量)
- poj 3177 Redundant Paths 边双连通分量
- POJ 3177Redundant Paths 边双连通分量
- POJ 3177 Redundant Paths(边双连通分量+缩点)
- POJ 3177 Redundant Paths <边双连通分量>
- am335x 内核源码分析2 LCD移植
- hihoCoder1331—扩展二进制数
- 异步加载数据,无限轮播,
- 20. Valid Parentheses
- caffe:把pb格式的文件均值(mean.binaryproto)转换成numpy格式的文件均值(mean.npy)
- poj 3177 Redundant Paths(Tarjan,边双连通分量)
- 机器学习-1-.py文件的导入问题
- iOS GPUImage研究序一:内置滤镜
- 深入理解MySQL索引
- yii2 表单小部件默认选中的方法
- PullToRefreshListView刷新下拉加载最简单用法
- Xgboost4j打包 java Ubuntu安装
- 详解Struts2的类型转换
- 第三周项目(4)