zoukankan      html  css  js  c++  java
  • 图论求割点模板

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    
    using namespace std;
    
    const int N=110;
    
    int dfn[N],low[N],head[N],vis[N];
    bool cut[N];
    int k,n,cnt,root;
    
    struct Edge{
        int to,nxt;
    }edge[N<<1];
    
    void addedge(int cu,int cv){
        edge[cnt].to=cv;
        edge[cnt].nxt=head[cu];
        head[cu]=cnt++;
    }
    
    void Tarjan(int u,int fa){
        int son=0;
        vis[u]=1;
        dfn[u]=low[u]=++k;
        for(int i=head[u];i!=-1;i=edge[i].nxt){
            int v=edge[i].to;
            if(vis[v]==1 && v!=fa)
                low[u]=min(low[u],dfn[v]);
            if(vis[v]==0){
                Tarjan(v,u);
                son++;
                low[u]=min(low[u],low[v]);
                if((u==root && son>1) || (u!=root && dfn[u]<=low[v]))
                    cut[u]=1;
            }
        }
        vis[u]=2;
    }
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        while(~scanf("%d",&n) && n){
            memset(head,-1,sizeof(head));
            memset(dfn,0,sizeof(dfn));
            memset(low,0,sizeof(low));
            memset(vis,0,sizeof(vis));
            memset(cut,0,sizeof(cut));
            cnt=0;
            int u,v;
            while(scanf("%d",&u) && u){
                while(getchar()!='
    '){
                    scanf("%d",&v);
                    addedge(u,v);
                    addedge(v,u);
                }
            }
            root=1;
            Tarjan(root,-1);
            int ans=0;
            for(int i=1;i<=n;i++)
                if(cut[i])
                    ans++;
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    halcon7月license
    软设考试成绩查询结果
    Halcon自学笔记
    Window_Store
    Windows_Store之2048
    基于C#开发的2048
    MVC+EF+EasyUI实现CRUD
    ASP.NET MVC Model验证总结
    浙江省三级数据库考试
    基于C#的短信发送
  • 原文地址:https://www.cnblogs.com/weeping/p/5705940.html
Copyright © 2011-2022 走看看