首页 > 其他 > 详细

P3388 【模板】割点(割顶)

时间:2020-08-05 00:37:57      阅读:109      评论:0      收藏:0      [点我收藏+]
#include <bits/stdc++.h>
#define inf 2333333333333333
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i)
//by war
//2020.8.4
using namespace std;

int n,m,x,y,cnt,ans;
int dfn[N],low[N],del[N];
bool vis[N];
struct node{
    int n;
    node *next;
}*e[N];

void in(int &x){
    int y=1;char c=getchar();x=0;
    while(c<0||c>9){if(c==-)y=-1;c=getchar();}
    while(c<=9&&c>=0){ x=(x<<1)+(x<<3)+c-0;c=getchar();}
    x*=y;
}
void o(int x){
    if(x<0){p(-);x=-x;}
    if(x>9)o(x/10);
    p(x%10+0);
}

void push(int x,int y){
    node *p;
    p=new node();
    p->n=y;
    if(e[x]==0)
        e[x]=p;
    else{
        p->next=e[x]->next;
        e[x]->next=p;
    }
}

void tarjan(int x,int fa){
    dfn[x]=low[x]=++cnt;
    vis[x]=1;
    int num=0;
    for(node *i=e[x];i;i=i->next){
        if(!dfn[i->n]){
            num++;
            tarjan(i->n,x);
            low[x]=min(low[x],low[i->n]);
            if(low[i->n]>=dfn[x] && x!=fa && !del[x]) {
                ans++;
                del[x]=1;
            }
        }
        else
            if(vis[i->n])
                low[x]=min(low[x],dfn[i->n]);
    }
    if(x==fa && num>1 && !del[x]){
        ans++;
        del[x]=1;
    }
}

int main(){
    in(n);in(m);
    For(i,1,m){
        in(x);in(y);
        push(x,y);
        push(y,x);
    }
    For(i,1,n) if(!dfn[i]) tarjan(i,i);
    o(ans);p(\n);
    For(i,1,n)
        if(del[i]) o(i),p( );
    return 0;
}

 

P3388 【模板】割点(割顶)

原文:https://www.cnblogs.com/war1111/p/13437041.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!