• P3388 【模板】割点(割顶)


    #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('
    ');
        For(i,1,n)
            if(del[i]) o(i),p(' ');
        return 0;
    }
  • 相关阅读:
    Django之form组件
    Http协议
    用户认证系统 django.contrib.auth模块
    自己关于Django的一些实践
    form标签
    jquery 遍历find()与children()的区别
    存储过程
    ASP.NET优化
    TRUNCATE与 DELETE
    视图的作用
  • 原文地址:https://www.cnblogs.com/war1111/p/13437041.html
Copyright © 2020-2023  润新知