• 无向图求割点 UVA 315 Network


    输入数据处理正确其余的就是套强联通的模板了

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <stack>
    #include <cstring>
    using namespace std;
    #define INF 0xfffffff
    #define maxn 106
    #define min(a,b) (a<b?a:b)
    /*无向图求桥和割点*/
    vector<int> G[maxn];
    int Father[maxn], time, dfn[maxn], low[maxn], n;
    bool cut[maxn];
    
    void init()
    {
        memset(Father, 0, sizeof(Father));
        memset(low, 0, sizeof(low));
        memset(dfn, 0, sizeof(dfn));
        memset(cut, false, sizeof(cut));
        time = 1;
        for(int i=1; i<=n; i++)
            G[i].clear();
    }
    void tarjan(int u,int father)
    {
        Father[u] = father;
        low[u] = dfn[u] = time ++;
        int len = G[u].size(), i, v;
    
        for(i=0; i<len; i++)
        {
            v = G[u][i];
            if(!low[v])
            {
                tarjan(v, u);
                low[u] = min(low[u], low[v]);
            }
            else if(v != father)
            {
                low[u] = min(low[u], dfn[v]);
            }
        }
    }
    void solve()
    {
        int i, RootSons = 0, v, num = 0;
        tarjan(1, 0);
        for(i=2; i<=n; i++)
        {
            v = Father[i];
            if(v == 1)
                RootSons ++;
            else if(dfn[v] <= low[i])
                cut[v] = true;
    
        }
        if(RootSons > 1)
            cut[1] = true;
        for(i=1; i<=n; i++)
        {
            if(cut[i])
                num ++;
        }
        printf("%d
    ", num);
    
    }
    
    int main()
    {
        int a, b;
        char ch;
        while(scanf("%d",&n), n)
        {
            init();
            while( scanf("%d",&a), a)
            {
                while( scanf("%d%c",&b,&ch) )
                {
                    G[a].push_back(b);
                    G[b].push_back(a);
                    if(ch == '
    ')
                        break;
                }
            }
    
            solve();
        }
        return 0;
    }
  • 相关阅读:
    MySQL的count函数注意点
    case when语句的报错问题
    redis的主从搭建与sentinel高可用服务的搭建
    解析范式(1NF-4NF)
    对SQL语言的相关学习
    ASP.NET Core MVC+EF Core项目实战
    ASP.NET Core +Highchart+ajax绘制动态柱状图
    tab页卡效果!
    今天我注册了迅雷快传
    触发器学习笔记(:new,:old用法)
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4463024.html
Copyright © 2020-2023  润新知