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 }
  • 相关阅读:
    for循环练习-----ATM取款
    面向对象基础项目----图书管理系统(数组)
    Java基础学习(二)-- 二维数组、String、StringBuffer以及类和对象之详解
    Java基础学习(一) -- Java环境搭建、数据类型、分支循环等控制结构、简单一维数组详解
    js 解决由于&#65279(bom文件格式)产生的空白行
    自适应网站设计对百度友好的关键:添加applicable-device标签(转)
    浏览器内核控制标签--meta
    HTML5的元素与结构标签
    <img>标签的补充
    HTML <head> 头部中的各类标签
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/9526171.html
Copyright © 2011-2022 走看看