标签:
点双:
1 void dfs(int u,int fa){ 2 dfn[u]=low[u]=++idx,stack[++top]=u; 3 for (int p=now[u],v=son[p];p;p=pre[p],v=son[p]) 4 if (!dfn[v]) dfs(v,u),low[u]=min(low[u],low[v]); 5 else if (v!=fa) low[u]=min(low[u],dfn[v]); 6 if (dfn[u]==low[u]) top--; // fa-u is bridge 7 if (low[u]==dfn[fa]){ //fa is cut-point 8 int v; ++cnt; 9 belong[fa].push_back(cnt); 10 do{v=stack[top--],belong[v].push_back(cnt);}while (v!=u); 11 } 12 }
边双:
1 void dfs(int u){ 2 dfn[u]=low[u]=++idx,stack[++top]=u,in[u]=1; 3 for (int p=now[u],v=son[p];p;p=pre[p],v=son[p]) 4 if (!dfn[v]) dfs(v),low[u]=min(low[u],low[v]); 5 else if (in[v]) low[u]=min(low[u],dfn[v]); 6 if (dfn[u]==low[u]){ 7 int v; ++cnt; 8 do{v=stack[top--],in[v]=0,bel[v]=cnt;}while (v!=u); 9 } 10 }
标签:
原文地址:http://www.cnblogs.com/chenyushuo/p/5103916.html