• TZOJ 2999 Network(连通图割点数量)


    描述

    A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N. No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.

    输入

    The input consists of several blocks of lines. Each block describes one network. In the first line of each block there is the number of places N < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places to which there is a direct line from this place. These at most N lines completely describe the network, i.e., each direct connection of two places in the network is contained at least in one row. All numbers in one line are separated by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0.

    输出

    The output contains for each block except the last in the input one line containing the number of critical places.

    样例输入

    5
    5 1 2 3 4
    0
    6
    2 1 3
    5 4 6 2
    0
    0

    样例输出

    1
    2

    题意

    求连通图关键点数量,关键点为去掉该点图不连通

    题解

    直接求割点数量

    代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int N=1e5+5;
     5 
     6 vector<int>G[N];
     7 int dfn[N],low[N],tot;
     8 bool cut[N];
     9 void tarjan(int u,int fa)
    10 {
    11     int child=0;
    12     dfn[u]=low[u]=++tot;
    13     for(int i=0;i<G[u].size();i++)
    14     {
    15         int v=G[u][i];
    16         if(!dfn[v])
    17         {
    18             tarjan(v,u);
    19             low[u]=min(low[u],low[v]);
    20             if(low[v]>=dfn[u]&&u!=fa)cut[u]=true;
    21             if(u==fa)child++;
    22         }
    23         low[u]=min(low[u],dfn[v]);
    24     }
    25     if(u==fa&&child>=2)cut[u]=true;
    26 }
    27 void init(int n)
    28 {
    29     tot=0;
    30     for(int i=0;i<=n;i++)
    31     {
    32         G[i].clear();
    33         dfn[i]=low[i]=0;
    34         cut[i]=false;
    35     }
    36 }
    37 int main()
    38 {
    39     int n,u,v;
    40     while(~scanf("%d",&n)&&n)
    41     {
    42         init(n);
    43         while(~scanf("%d",&u)&&u)
    44         {
    45             while(getchar()!='
    ')
    46             {
    47                 scanf("%d",&v);
    48                 G[u].push_back(v);
    49                 G[v].push_back(u);
    50             }
    51         }
    52         tarjan(1,1);
    53         int ans=0;
    54         for(int i=1;i<=n;i++)if(cut[i])ans++;
    55         printf("%d
    ",ans);
    56     }
    57     return 0;
    58 }
  • 相关阅读:
    while,dowhile,for循环和forin
    position:fixed;支持ie6,清除e6下抖动。
    数组concat()和slice()方法
    函数内arguments.callee的用法
    [转]十天学习PHP之第六天(PHP)学会添加删除修改数据 (20091125 14:26)
    [转]十天学习PHP之第三天(PHP)学会构建数据库
    [转]十天学习PHP之第二天(PHP)掌握php的流程控制
    php集成软件VertrigoServ(PHP安装)
    [转]十天学习PHP之第一天(PHP)基础知识
    PHP入门
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/9526171.html
Copyright © 2020-2023  润新知