首页 > 其他分享 >割点板子

割点板子

时间:2022-11-26 12:13:10浏览次数:46  
标签:int 割点 板子 dfn low go hd

一些直白的理解,和标准定义有差别,但也足够了

 

点双连通:一个图任意去掉一个点后仍然联通;    边双连通同理

割点:去掉某个点后,图不连通      割边同理

 

求割点 ( low[y]>=dfn[x] )

#include <bits/stdc++.h>
using namespace std ;
 const int N=2*1e4+3,M=5*1e5+2;
 int dfn[N],low[N],n,m,pool;
 int ans,cut[N];
 int all,go[M],nxt[M],hd[N];
 void add(int x,int y){
     all++; go[all]=y,nxt[all]=hd[x],hd[x]=all;
 }
 void tar(int x,int fa){
     dfn[x]=low[x]=++pool;
     
     int y,c=0;
     for(int i=hd[x];i;i=nxt[i]){
        y=go[i];
      if(!dfn[y]){
          c++,tar(y,x),low[x]=min(low[x],low[y]);
          
          if(fa==0&&c>1||fa&&dfn[x]<=low[y]) 
          ans+=(cut[x]?0:1),cut[x]=1;
      }    
      else if(y!=fa) low[x]=min(low[x],dfn[y]);
    }
 }
 int main(){
     int i,x,y;
     cin>>n>>m;
     for(i=1;i<=m;i++) 
     cin>>x>>y,add(x,y),add(y,x);
    for(i=1;i<=n;i++) if(!dfn[i]) tar(i,0);
    cout<<ans<<'\n';
    for(i=1;i<=n;i++) if(cut[i]) cout<<i<<' ';
 }
 
 
 

 

标签:int,割点,板子,dfn,low,go,hd
From: https://www.cnblogs.com/towboa/p/16927192.html

相关文章

  • 高精度板子
     #include<bits/stdc++.h>usingnamespacestd;intcompare(stringstr1,stringstr2){if(str1.length()>str2.length())return1;elseif(str1.length(......
  • 一些板子
    离散化://离散化,可以处理一些跨越区间比较大的时候的位置关系,空间更紧凑intn,m;inta[N],b[N],c[N];intcnt=0;//lower_bound第一个大于等于x的数//upper_bound......
  • CSP-J/S & NOIP 常用板子大全 !
    HNCSP-J/S2022RP++!序号算法①SPFA②并查集③最小生成树④拓扑排序⑤堆⑥字典树N懒得加了1.SPFA题目链接题目描述输入......
  • 快速幂(板子)
    先讨论无需取模的当b为偶数时:ab=a(b/2)*2=(a2)b/2当b为奇数时:ab=a*ab-1=a*(a2)(b-1)/2如 28=(22)4     27=2*(22)3所以,我们可以如此迭代下......
  • 一个很好用的 C++ 高精度整数板子
    点击查看代码typedeflonglongll;typedeflongdoubleld;typedefcomplex<ld>pt;constintMOD=1e9+7;constldPI=acos(-1.L);template<classT>struc......
  • 最短路板子
    floyedO(n^3) f[i][j]=min(f[i][j],f[i][k]+f[k][j]) memset(f,inf,sizeof(f));for(i=1;i<=m;i++)cin>>x>>y>>z,f[x][y]=f[y][x]=z;for......
  • 有理数逆元板子
    template<intM=1000000007>structrational{llp,q;rational(llp=0,llq=1):p(p),q(q){}rationaloperator+(constrational&rhs)const{......
  • kmp板子
    主串a,模式串b,求b在a中出现的位置 #include<iostream>#include<algorithm>#include<cstring>usingnamespacestd;constintN=1e6+4;intla,lb;intf[N],p[N]......
  • Hash表板子
    #include<bits/stdc++.h>usingnamespacestd;#definelllonglong#defineullunsignedlonglongullrx=1e9+7;llrand(llx,lly){rx*=998244353;returnrx%(y-x+......
  • 普及-的并查集(都是板子)
        #include<bits/stdc++.h>usingnamespacestd;constintN=1e5+7;structNode{ intbn,ed,t;}a[N];intf[N];intfind(intx){returnx==f[x]?x:......