• poj 1523 SPF 无向图关节点


    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    const int N=1000+5;
    int g[N][N],vis[N],low[N],dfn[N],sub[N],dep,n,son;
    
    void dfs(int u)
    {
        for(int v=1;v<=n;v++)
        {
            if(g[u][v])
            {
                if(!vis[v])
                {
                    vis[v]=1;
                    dep++;
                    dfn[v]=low[v]=dep;
                    dfs(v);
                    low[u]=min(low[u],low[v]);
                    if(low[v]>=dfn[u])
                    {
                        if(u==1) son++;
                        else sub[u]++;
                    }
                }
                else
                  low[u]=min(low[u],dfn[v]);
            }
        }
    }
    
    int main()
    {
        int i,j,u,v,flag,cas=0;
        while(~scanf("%d",&u))
        {
            n=0;
            n=max(n,u);
            if(u==0) break;
            memset(g,0,sizeof(g));
            scanf("%d",&v);
            n=max(n,v);
            g[u][v]=g[v][u]=1;
            while(~scanf("%d",&u))
            {
                if(u==0) break;
                n=max(n,u);
                scanf("%d",&v);
                n=max(n,v);
                g[u][v]=g[v][u]=1;
            }
            memset(vis,0,sizeof(vis));
            memset(sub,0,sizeof(sub));
            dep=1;
            son=0;
            dfn[1]=low[1]=vis[1]=1;
            dfs(1);
            if(son>1) sub[1]=son-1;
            flag=0;
            if(cas>0) printf("
    ");
            printf("Network #%d
    ",++cas);
            for(i=1;i<=n;i++)
            {
                //printf("%d
    ",sub[i]);
                if(sub[i])
                {
                    flag=1;
                    printf("  SPF node %d leaves %d subnets
    ",i,sub[i]+1);
                }
            }
            if(!flag)
                printf("  No SPF nodes
    ");
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    01 . Nginx简介及部署
    01 . Ansible原理部署及简单应用
    vue css module
    Expected linebreaks to be 'LF' but found 'CRLF'.
    vue SPA设计 history hash
    vue3 createComponent
    vue3 template refs dom的引用、组件的引用、获取子组件的值
    vue3 父组件给子组件传值 provide & inject
    vue3生命周期
    CSS3 transform变换
  • 原文地址:https://www.cnblogs.com/xryz/p/4847793.html
Copyright © 2020-2023  润新知