【模板】割点判定

引理:若图中一个点是割点,则满足:

  • 若该点不是搜索树的根节点:以该点为根的搜索子树中任意节点的 low[] 值均大于等于该点的时间戳 dfn[]。
  • 若该点是搜索树的根节点,则必须有两个或两个以上的搜索子树上的节点满足第一条性质。

割点的定义:将该点删去后,新生成的图(不包括删去的顶点)会分为两个或两个以上的不连通子图。

代码如下

#include <bits/stdc++.h>
using namespace std;
const int maxv=2e4+10;
const int maxe=1e5+10;

inline int read(){
    int x=0,f=1;char ch;
    do{ch=getchar();if(ch=='-')f=-1;}while(!isdigit(ch));
    do{x=x*10+ch-'0';ch=getchar();}while(isdigit(ch));
    return f*x;
}

struct node{
    int nxt,to;
}e[maxe<<1];
int tot=1,head[maxv];
inline void add_edge(int from,int to){
    e[++tot]=node{head[from],to},head[from]=tot;
}

int n,m;
int dfs_clk,root,sum,dfn[maxv],low[maxv];
bool cut[maxv];

void read_and_parse(){
    n=read(),m=read();
    for(int i=1,x,y;i<=m;i++){
        x=read(),y=read();
        if(x==y)continue;
        add_edge(x,y),add_edge(y,x);
    }
}

void dfs(int u,int fe){
    int flag=0;
    dfn[u]=low[u]=++dfs_clk;
    for(int i=head[u];i;i=e[i].nxt){
        int v=e[i].to;
        if(!dfn[v]){
            dfs(v,i);
            low[u]=min(low[u],low[v]);
            if(low[v]>=dfn[u]){
                ++flag;
                if(!cut[u]&&(u!=root||flag>1))cut[u]=1,++sum;
            }
        }
        else if(i!=(fe^1))low[u]=min(low[u],dfn[v]);
    }
}

void solve(){
    for(int i=1;i<=n;i++)if(!dfn[i])root=i,dfs(i,0);
    printf("%d\n",sum);
    for(int i=1;i<=n;i++)if(cut[i])printf("%d ",i);
}

int main(){
    read_and_parse();
    solve();
    return 0;   
}

转载于:https://www.cnblogs.com/wzj-xhjbk/p/10511151.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值