zoukankan      html  css  js  c++  java
  • 无向图割点模板

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int n,m,first[200005],next[200005],to[200005],tot,dfn[20005],low[20005],num,ans;
     4 bool f[20005];
     5 void add(int x,int y)
     6 {
     7     tot++;
     8     next[tot]=first[x];
     9     first[x]=tot;
    10     to[tot]=y;
    11 }
    12 void tarjan(int x,int root)
    13 {
    14     num++;
    15     dfn[x]=low[x]=num;
    16     int flag=0;
    17     for(int i=first[x];i;i=next[i])
    18     {
    19         int y=to[i];
    20         if(dfn[y]==0)
    21         {
    22             tarjan(y,root);
    23             low[x]=min(low[x],dfn[y]);
    24             if(dfn[x]<=low[y])
    25             {
    26                 flag++;
    27                 if(x!=root||flag>1) 
    28                 {
    29                     if(f[x]==false) ans++;
    30                     f[x]=true;
    31                 }
    32             }
    33         }
    34         else low[x]=min(dfn[y],low[x]);
    35     }
    36     
    37 }
    38 int main()
    39 {
    40     scanf("%d%d",&n,&m);
    41     for(int i=1;i<=m;i++)
    42     {
    43         int x,y;
    44         scanf("%d%d",&x,&y);
    45         add(x,y);
    46         add(y,x);
    47     }
    48     for(int i=1;i<=n;i++) if(dfn[i]==0) tarjan(i,i);
    49     printf("%d
    ",ans);
    50     for(int i=1;i<=n;i++) 
    51     {
    52         if(f[i]==true) printf("%d ",i);
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    php apc
    nginx https
    js弹出确认框,挺全
    websocket nodejs
    nodejs express测试
    【C++】Mandelbrot集绘制(生成ppm文件)
    【Scheme】Huffman树
    【Scheme】符号求导
    【Scheme】树结构
    【Scheme】序列的操作
  • 原文地址:https://www.cnblogs.com/jiuduSHENBENG/p/11229688.html
Copyright © 2011-2022 走看看