博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【POJ】3177 Redundant Paths
阅读量:7218 次
发布时间:2019-06-29

本文共 982 字,大约阅读时间需要 3 分钟。

【算法】边双连通分量

【题意&题解】http://blog.csdn.net/geniusluzh/article/details/6619575 (注意第一份代码是错误的)

一些细节:

1.判断桥只能在树边判断,不能在反向边判断,体现在程序中注释的wrong位置。

2.标记桥要双向标记。

3.第二次dfs的时候记得不走已染色的点,否则会陷入环中。

核心判断:

1.未访问过:取low

2.未访问过:判桥

3.访问过:取dfn

#include
#include
using namespace std;const int maxn=5010,maxm=10010;struct edge{
int u,v,from;}e[maxm*3];int first[maxn],dfn[maxn],dfsnum,low[maxn],iscut[maxn],cc[maxn],ccnum,n,m,tot,degree[maxn];void insert(int u,int v){tot++;e[tot].u=u;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}int tarjan(int x,int fa){ dfn[x]=low[x]=++dfsnum; for(int i=first[x];i;i=e[i].from) if(e[i].v!=fa) { int y=e[i].v; if(!dfn[y]) { tarjan(y,x); low[x]=min(low[x],low[y]); if(low[y]>dfn[x])iscut[i]=1,iscut[i%2?i+1:i-1]=1; } else low[x]=min(low[x],dfn[y]);// if(low[y]
View Code

 

转载于:https://www.cnblogs.com/onioncyc/p/6052466.html

你可能感兴趣的文章
2012各大IT公司校招笔试题整理
查看>>
phpcms 后台分页
查看>>
《需求工程》阅读笔记之六
查看>>
架构阅读笔记5
查看>>
IIS5.1使用虚拟目录部署网站
查看>>
Git 深度学习填坑之旅三(分支branch、远程操作)
查看>>
括号匹配问题
查看>>
UVA 10766 Organising the Organisation
查看>>
「美团 CodeM 复赛」城市网络
查看>>
python 将Excel表格中的一列数据转化成多行数据
查看>>
Go多线程与channel通信
查看>>
找水王
查看>>
多个线程之间共享数据的方式(卖票问题,存取款问题)
查看>>
观察者模式
查看>>
Bzoj2882 工艺 [线性算法]
查看>>
Bzoj2251 [2010Beijing Wc]外星联络
查看>>
python 发送邮件
查看>>
在凡客四个月的工作总结
查看>>
Qt颜色下拉框
查看>>
31、springboot与任务
查看>>