zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    为什么我会被淘汰?
    2017-3-27日碎碎念
    (原创)我对未来的人类的发展,以及AI技术发展的一些思考。
    八大排序算法图文讲解
    PE病毒初探——向exe注入代码
    [转]Patch文件结构详解
    芝麻信用商家接入指南
    如何成为一名好的程序员的一些个人经验
    .NET CoreCLR开发人员指南(上)
    七牛云:ckeditor JS SDK 结合 C#实现多图片上传。
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/9526171.html
Copyright © 2011-2022 走看看