Network

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 12551   Accepted: 5771

Description

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.

Input

The input file 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;

Output

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

Sample Input

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

Sample Output

1
2

Hint

You need to determine the end of one line.In order to make it's easy to determine,there are no extra blank before the end of each line.
 
 //2016.9.16
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 105 using namespace std; int n, root, book[N], edge[N][N], num[N], low[N], Index;
//book用来记录哪些点是割点,edge以邻接矩阵保存图,num[i]为顶点i的时间戳,low[i]为顶点i不经过父顶点所能回到的最小时间戳 void dfs(int cur, int fa)
{
int child = ;
Index++;
num[cur] = low[cur] = Index;
for(int i = ; i <= n; i++)
{
if(edge[cur][i]==)
{
if(num[i] == )
{
child++;
dfs(i, cur);
low[cur] = min(low[cur], low[i]);
if(cur!=root && low[i]>=num[cur])
book[cur] = ;
if(cur==root && child==)
book[cur] = ;
}else if(i != fa)
{
low[cur] = min(low[cur], num[i]);
}
}
}
return;
} int main()
{
int u, v;
while(scanf("%d", &n) && n)
{
memset(edge, , sizeof(edge));
memset(low, , sizeof(low));
memset(num, , sizeof(num));
memset(book, , sizeof(book));
Index = ; root = ;
while(scanf("%d", &u) && u)
{
while(getchar() != '\n')
{
scanf("%d", &v);
edge[u][v] = ;
edge[v][u] = ;
}
}
dfs(, root);
int cnt = ;
for(int i = ; i <= n; i++)
if(book[i])cnt++;
printf("%d\n", cnt);
} return ;
}

POJ1144(割点)的更多相关文章

  1. POJ1144(割点入门题)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11378   Accepted: 5285 Descript ...

  2. [POJ1144][BZOJ2730]tarjan求割点

    求割点 一种显然的n^2做法: 枚举每个点,去掉该点连出的边,然后判断整个图是否联通 用tarjan求割点: 分情况讨论 如果是root的话,其为割点当且仅当下方有两棵及以上的子树 其他情况 设当前节 ...

  3. poj1144 tarjan求割点

    poj1144 tarjan求割点 额,算法没什么好说的,只是这道题的读入非常恶心. 注意,当前点x是否是割点,与low[x]无关,只和low[son]和dfn[x]有关. 还有,默代码的时候记住分目 ...

  4. poj1144 求不同割点的个数

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11914   Accepted: 5519 Descript ...

  5. poj1144 Network【tarjan求割点】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html   ---by 墨染之樱花 [题目链接]http://poj.org/p ...

  6. POJ1144 Network(割点)题解

    Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...

  7. (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. POJ1144:Network(无向连通图求割点)

    题目:http://poj.org/problem?id=1144 求割点.判断一个点是否是割点有两种判断情况: 如果u为割点,当且仅当满足下面的1条 1.如果u为树根,那么u必须有多于1棵子树 2. ...

  9. [poj1144]Network(求割点模板)

    解题关键:割点模板题. #include<cstdio> #include<cstring> #include<vector> #include<stack& ...

随机推荐

  1. Nexus搭建私服 学习

    为什么要搭建nexus私服 因为有些公司不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以,有必要再局域网里找一台有外网权限的机器.搭建nexus私服,然后开发人员连接到这台私服 ...

  2. B进制加法(洛谷1604)

    分析:码农题,照这模拟就行,高精度的B进制,注意字符串反转的技巧. #include <iostream> #include <cstdio> #include <cst ...

  3. jQuery Ajax 二次封装

    jQuery Ajax通用js封装 第一步:引入jQuery库 <script type="text/javascript" src="<%=path%> ...

  4. spark 文件系统Alluxio(之前名为Tachyon)

    http://www.alluxio.org/documentation/v1.0.0/cn/ http://www.winseliu.com/blog/2016/04/15/alluxio-quic ...

  5. ReactiveNative学习之Diff算法

    React 源码剖析系列 - 不可思议的 react diff深入浅出React(四):虚拟DOM Diff算法解析React diff 算法总结链接引用的文章React出于性能的考虑,为了避免频繁操 ...

  6. LAMP优化

    LAMP系统优化是非常必要的,一个好的优化能使系统运作的越快,从而提高工作效率,下面我将从几方面给大家详细介绍下LAMP系统优化的内容. 一.硬件优化 1.升级硬件的一般规则:对于 PHP 脚本而言, ...

  7. Windwos下 php mysql apache 环境配置

    一.下载所需软件: 1.安装Windows组件: 安装Apache的前  必须安装  VC11 vcredist_x86.exe (64位请下载vcredist_x64.exe),选择时尽量选择英文版 ...

  8. ZOJ 3927 Programming Ability Test

    水题,判断一下加起来是否大于等于80 #include<cstdio> #include<cstring> #include<cmath> #include< ...

  9. 开源免费的C/C++网络库(c/c++ sockets library)补充

    (1)ACE 庞大.复杂,适合大型项目.开源.免费,不依赖第三方库,支持跨平台. http://www.cs.wustl.edu/~schmidt/ACE.html (2)Asio Asio基于Boo ...

  10. bootstrap tab标签页

    <ul id="myTab" class="nav nav-tabs"> <li class="active"> & ...