Cut point cut point determination search rules

If x is a root of the subtree search for the presence of a dfn [x] <= low [y] (x is a root if you need two or more) cut point x =

#include<iostream>
using namespace std;
const int N =10010;
int head[N],nex[N<<1],e[N<<1],tot;
int dfn[N],low[N],n,m,num,root;
bool cut[N<<1];

void add(int x,int y){
    e[++tot]=y,nex[tot]=head[x],head[x]=tot;
}

void tarjan(int x){
    dfn[x]=low[x]=++num;
    int flag=0;
    for(int i=head[x];i;i=nex[i]){
        int y=e[i];
        if(!dfn[y]){
            tarjan(y,i);//递归搜索回溯值
            low[x]=min(low[x],low[y]);
            if(low[y]>=dfn[x]){
                flag++;//计算合格y的个数
                if(x!=root||flag>1) cut[x]=1;
            }
        }
        else low[x]=min(low[x],dfn[y]);
    }
}


int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        if(x==y) continue;
        add(x,y),add(y,x);
    }
    for(int i=1;i<=n;i++)
        if(!dfn[i]) root=i,tarjan(i,0);
    for(int i=2;i<tot;i+=2)
        if(cut[i])
            cout<<i<<' ';
    return 0;
}
Published 38 original articles · won praise 5 · Views 836

Guess you like

Origin blog.csdn.net/Fooooooo/article/details/104896567