zoukankan      html  css  js  c++  java
  • Tarjan三合一

    扔个代码就跑系列。。

     1 //It's my ass?
     2 //noip rp++;
     3 
     4 
     5 int dfn[233333]={};
     6 int stack[233333]={};
     7 int low[233333]={};
     8 bool v[233333]={};
     9 bool inq[233333]={};
    10 int t=0,Bcnt=0;
    11 
    12 
    13 void tarjan_lca(int u,int father)
    14 {
    15     v[u]=1;
    16     dep[u]=1;
    17     father[u]=u;
    18     for (int i=g2[u];i;i=e2[i].next)
    19       if (v[e2[i].to])
    20         lca[e2[i].num]=find(e[i].to);
    21     for (i=g[u];i;i=e[i].next)
    22       if (e[i].to!=father)
    23         if (!v[e[i].to])
    24           {
    25             tarjan_lca(e[i].to);
    26             father[e[i].to]=u;
    27             dep[u]+=dep[e[i].tp];
    28           }
    29 }
    30 
    31 
    32 void tarjan_connected(int u)
    33 {
    34     inq[u]=1;dfn[u]=low[u]=++t;
    35     stack[++top]=u;
    36     for (int i=g[u];i;i=e[i].next)
    37       if (e[i].to!=father)
    38         {
    39             if (!v[e[i].to])
    40               {
    41                  tarjan_connected(e[i].to);
    42                  low[u]=min(low[u],low[e[i].to]);
    43               }
    44             else
    45               if (inq[e[i].to])
    46                 low[u]=min(low[u],dfn[e[i].to]);
    47         }
    48     int j;
    49     if (dfn[u]==low[u])  
    50       {  
    51         do  
    52           {  
    53             j=stack[--top];  
    54             inq[j]=false;  
    55             belong[j]=Bcnt;  
    56           }  
    57         while (j!=u);  
    58         Bcnt++;  
    59       }  
    60 }
    61 
    62 
    63 
    64 void tarjan_cut(int u, int father) //father 是u的父节点  
    65 {     
    66     father[u]=father;  
    67     int i,j,k;  
    68     low[u]=dfn[u]=++t;  
    69     for(i=g[u];i;i=e[i].next)
    70       { 
    71         if(!dfn[e[i].to])
    72           {  
    73             tarjan(v,u);  
    74             low[u]=min(low[u],low[v]);  
    75             if(low[v]>low[u])
    76                u,v为桥/u,v为割点的话,low[v]>=low[u] 
    77           }  
    78         else //该顶点已被访问过,更新该搜索的顶点的最早祖先  
    79           if(father!=v) //连到父节点的回边不考虑,否则求不出桥  
    80             low[u]=min(low[u],dfn[v]);  
    81       }    
    82 }
    View Code
  • 相关阅读:
    html5---音频视频基础一
    SQL--数据库性能优化详解
    微信--入门开发
    MVC----基础
    jquery -----简单分页
    sql优化
    集合的总结
    java并发编程与高并发解决方案
    java中boolean类型占几个字节
    正则表达式小结
  • 原文地址:https://www.cnblogs.com/yz12138/p/6076429.html
Copyright © 2011-2022 走看看