图论--割点--Tarjan模板

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
using namespace std;
const int N=100010;
int head[N],ver[N*2],Next[N*2];
int dfn[N],low[N],n,m,tot,num;
bool brige[N*2];
void add(int x,int y){
    ver[++tot]=y,Next[tot]=head[x],head[x]=tot;
}
void tarjan(int x,int inedge)
{

    dfn[x]=low[x]=++num;
    for(int i=head[x];i;i=Next[i])
    {
        int y=ver[i];
        if(!dfn[y])
        {
            tarjan(y,i);
            low[x]=min(low[x],low[y]);
            if(low[y]>dfn[x])
            {
                brige[i]=brige[i^1]=1;
            }
        }
        else if(i!=(inedge^1))
            low[x]=min(low[x],dfn[y]);
    }
}
int main()
{
    cin>>n>>m;
    tot=1;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        add(x,y);
        add(y,x);
    }
    for(int i=1 ;i<=n;i++)
        if(!dfn[i]) tarjan(i,0);
    int ans=0;
    for(int i=2;i<tot;i+=2)
    {
        if(brige[i])
        {
           printf("%d %d
",ver[i^1],ver[i]);
        }
    }
}
原文地址:https://www.cnblogs.com/lunatic-talent/p/12798671.html