【模板】图的割点

lrj
dfn:发现时间
low:子树中可以追溯到最早的节点的发现时间

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=501000;
const int N=101000;
struct E {int to,nxt;}edge[M*2];
int low[N],dfn[N],Time=0;
int idx[N],tot=1;
bool iscut[N];
int n,m,ans;
void addedge(int from,int to){
    edge[tot].to=to;edge[tot].nxt=idx[from];idx[from]=tot++;
}
void dfs(int x,int fa){
    int child=0;
    dfn[x]=low[x]=++Time;
    for(int t=idx[x];t;t=edge[t].nxt){
        E e=edge[t];
        if(!dfn[e.to]){
            child++;
            dfs(e.to,x);
            low[x]=min(low[e.to],low[x]);
            if(low[e.to]>=dfn[x]) iscut[x]=1;
        }
        else if(e.to!=fa)
            low[x]=min(low[x],dfn[e.to]);
    }
    if(fa==-1 && child==1) iscut[x]=0;
}
int main(){
//  freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        addedge(x,y);addedge(y,x);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++) if(iscut[i]) ans++;
    printf("%d\n",ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值