【算法】边双连通分量
【题意&题解】http://blog.csdn.net/geniusluzh/article/details/6619575 (注意第一份代码是错误的)
一些细节:
1.判断桥只能在树边判断,不能在反向边判断,体现在程序中注释的wrong位置。
2.标记桥要双向标记。
3.第二次dfs的时候记得不走已染色的点,否则会陷入环中。
核心判断:
1.未访问过:取low
2.未访问过:判桥
3.访问过:取dfn
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
#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]