描述

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()!='\n')
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\n",ans);
56     }
57     return 0;
58 }

转载于:https://www.cnblogs.com/taozi1115402474/p/9526171.html

TZOJ 2999 Network(连通图割点数量)相关推荐

  1. 双连通图强连通图概念解释以及tarjan算法求解该类问题总结

    最近看了看类的相关题,感觉简单的题过于模板,但是对于难题的转化,如果对与这方面的概念不清楚,很难写,故总结一下. PS:博客里部分内容会和离散数学中的图论知识有联系,如果没有了解过相关知识可能比较难理 ...

  2. Tarjan 算法思想求强连通分量及求割点模板(超详细图解)

    割点定义 在一个无向图中,如果有一个顶点,删除这个顶点及其相关联的边后,图的连通分量增多,就称该点是割点,该点构成的集合就是割点集合.简单来说就是去掉该点后其所在的连通图不再连通,则该点称为割点. 若 ...

  3. 有趣题目和认知合集(持续更新)

    写写对一些算法的理解,挂几个有意思的题,可能也会挂几个板子题 算法理解偏向于能懂即可,没有严格的证明 快乐几何 [1.2]Volatile Kite 点到直线 快乐搜与暴力 [2.4]Short Co ...

  4. 2019金华正睿集训总结

    emmm-蒟蒻第一次出来集训,也是2019年noip(现在应该叫csp的说)前最后一次外出集训- 感觉压力好大啊-毕竟才学了不到一年啊- 但不管怎样,接下来几天要好好加油啊! DAY1 仅自己用的链接 ...

  5. 强连通,奇怪的缩点学习笔记?

    缩点,难难难,不想学呜呜呜.板子:P3387 [模板]缩点 还好吧正常点,考虑对于一个有向图,进行缩点.呜呜呜我是废物.说几个我学的时候想了一段时间的问题: (dfn[u]表示顶点u第几个被(首次)访 ...

  6. 边双连通和点双连通(连通性)

    一.时间戳: 1.一种记录时间的方式,像DFS序 2.防伪,不重复,精确到时刻 3.对每个节点而言,时间戳一般用dfn[i]来表示,最小时间戳一般用low[i]来表示 二.一些边: 1.前向边:当前点 ...

  7. 1126 Eulerian Path

    主要考英语或者数学基础. 一幅连通图的奇点个数为0或2时才能够被一笔画. 连通图的判断用DFS来计数. 连通图+0个奇点:Eulerian 连通图+2个奇点:semi-Eulerian 非连通图/连通 ...

  8. Co-occurrence网络图在R中的实现

    作者:陈亮 单位:中科院微生物所 编者按:上个月菌群月坛,在军科院听取王军组陈亮博士分享网络分析的经验,不仅使我对网络的背景知识有了更全面的认识,更使我手上一个关于菌根的课题有极大的启示.这么好的知识 ...

  9. 理解 neutron(15):Neutron Linux Bridge + VLAN/VXLAN 虚拟网络

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

最新文章

  1. 使用TypeScript映射和条件类型使React组件更出色
  2. 技术流 | 手把手教你用Python设计一个命令行界面
  3. 通过容器提交镜像(docker commit)以及推送镜像(docker push)笔记
  4. TiDB 源码阅读系列文章(十九)tikv-client(下)
  5. Servlet简介与Servlet和HttpServlet运行的流程
  6. python之强大的日志模块
  7. Go gin运行原理
  8. Mysql从某个字段的每类中取最大最小值
  9. 2019年Java架构师必读书籍
  10. 探索发现:平台云——云的新风向
  11. 12 月份 10 个新鲜的 jQuery 插件和教程
  12. 为什么可以通过类名调用静态方法?
  13. 2010年,您还不“工作流”吗?
  14. android 动态壁纸开发
  15. Super Saiyan 寻找创业合伙人
  16. Linux和windows下多线程的区别
  17. 基于增量更新的协同过滤
  18. mysql数据量很少查询却很慢_Mysql索引
  19. 一、阿里矢量图标(字体图标)
  20. ARM汇编程序——加法

热门文章

  1. asp隐藏邮箱部分字符_asp.net core 中使用 signalR(二)
  2. python Iterable
  3. WaveShaperNode
  4. Elasticsearch Restful API
  5. Element NavMenu
  6. linux 用户及权限管理
  7. php中this的使用技巧,JavaScript中this关键字使用方法详解
  8. 数据双向绑定_手写 Vue3 数据双向绑定 理解Proxy
  9. Redis学习总结(18)——Redis 常见面试题复习
  10. Spring Boot学习总结(6)——SpringBoot解决ajax跨域请求问题的配置