zoukankan      html  css  js  c++  java
  • 双连通分量模板

    点双:

     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 }
  • 相关阅读:
    Contest
    【HDU2224】The shortest path(双调欧几里得dp)
    UVa400.Unix ls
    一些脚本
    省赛总结
    一些事
    一些笔记
    CSU 1526: Beam me out!
    以后可能用到的命令
    Codeforces Round #297 (Div. 2)
  • 原文地址:https://www.cnblogs.com/chenyushuo/p/5103916.html
Copyright © 2011-2022 走看看