Network
 

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.
 
  这道题就是求无向图的割顶,一般用tarjan算法。
  刘汝佳老师的书上有写,还注明要注意一些地方,并称之为"写错",可我觉得有些地方没注意只是不严谨,并不影响正确性……
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
const int maxm=;
int low[maxn],vis[maxn],tim;
int cnt,fir[maxn],to[maxm<<],nxt[maxm<<];
bool iscut[maxn];
void addedge(int a,int b){
nxt[++cnt]=fir[a];fir[a]=cnt;to[cnt]=b;
}
void DFS(int node,int fa){
low[node]=vis[node]=++tim;
int child=;
for(int i=fir[node];i;i=nxt[i])
if(vis[to[i]])
low[node]=min(low[node],vis[to[i]]);
else{
child++;
DFS(to[i],node);
low[node]=min(low[node],low[to[i]]);
if(low[to[i]]>=vis[node])
iscut[node]=true;
}
if(fa==-&&child<=)
iscut[node]=false;
}
int main(){
int a,b,n;
while(~scanf("%d",&n)&&n){
tim=;cnt=;
memset(vis,,sizeof(vis));
memset(fir,,sizeof(fir));
memset(iscut,,sizeof(iscut));
while(~scanf("%d",&a)&&a){
char c;
while((c=getchar())!='\n'){
scanf("%d",&b);
addedge(a,b);
addedge(b,a);
}
}
DFS(,-);
int ans=;
for(int i=;i<=n;i++)
if(iscut[i])
ans++;
printf("%d\n",ans);
}
return ;
}

图论(无向图的割顶):POJ 1144 Network的更多相关文章

  1. POJ 1144 Network(无向图的割顶和桥模板题)

    http://poj.org/problem?id=1144 题意: 给出图,求割点数. 思路: 关于无向图的割顶和桥,这篇博客写的挺不错,有不懂的可以去看一下http://blog.csdn.net ...

  2. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  3. poj 1144 Network(无向图求割顶数)

    题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...

  4. POJ 1144 Network【割顶】

    学习的这一篇:https://www.byvoid.com/blog/biconnect 割顶:对于无向图G,如果删除某个点u后,连通分量数目增加,称u为图的关节点或者割顶 u为割顶的条件: (1)u ...

  5. POJ1144 Network 无向图的割顶

    现在打算重新学习图论的一些基础算法,包括像桥,割顶,双连通分量,强连通分量这些基础算法我都打算重敲一次,因为这些量都是可以用tarjan的算法求得的,这次的割顶算是对tarjan的那一类算法的理解的再 ...

  6. UVA 315 :Network (无向图求割顶)

    题目链接 题意:求所给无向图中一共有多少个割顶 用的lrj训练指南P314的模板 #include<bits/stdc++.h> using namespace std; typedef ...

  7. POJ 1144 Network(无向图连通分量求割点)

    题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...

  8. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  9. poj 1144 Network 无向图求割点

    Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...

随机推荐

  1. jquery生产和开发的区别

    今天说一下jquery生产和开发的区别,在我们下载jquery的时候,会有两个下载链接,一个是jquery.min.js .迷你版 (生产),另一个是 jquery.js .开发版 .不知道的人可能就 ...

  2. Android图表引擎AChartEngine之折线图使用

    最近在帮老师做一个课题,其中app端需要显示折线图以便直观地看数据波动,上网查了些资料后发现了这款图标引擎,另外感谢李坤老师的博客,帮助很大. 废话不多说,下面写代码. 一.AChartEngine是 ...

  3. js 表单不为空,数字长度验证

    $(document).ready(function() {    //聚焦第一个输入框    $("#invtype").focus();                     ...

  4. Linux下JDK环境变量配置

    JDK官方下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 我的下载路 ...

  5. opencv 常用函数介绍

    ××××××××××××××××××××××××××××××××××××××× CvScalar imgmean,imgstd; double imgmax,imgmin; cvAvgSdv(img, ...

  6. 【POJ2752】【KMP】Seek the Name, Seek the Fame

    Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...

  7. Visual Studio 2013环境下操作vc6/vc7/vc8等低版本平台项目【编译|生成|调试】

    现代化的开发环境,微软一直在推出更新换代,我们所处的技术环境在日新月异的变化:不过在中国多数人们一边疲惫的追赶着时代的步伐,一边坚守着自己所获悉所掌握的那些紧吧吧的知本.对技术工具的掌握并非他们所想要 ...

  8. Linux系统、版本、CPU、内存查看、硬盘空间

    查看系统版本:lsb_release -a [root@localhost /]# lsb_release -a LSB Version:    :core-4.0-amd64:core-4.0-no ...

  9. underscorejs-size学习

    2.24 size 2.24.1 语法: _.size(list) 2.24.2 说明: 返回列表的长度. 示例一:返回数组.对象.字符串的长度 //取数组的长度 var length length ...

  10. 字体圆润属性的使用-webkit-font-smoothing: antialiased

    字体渲染和抗锯齿技术 据称该属性在window下不起作用,不知win10如何,但是在OS和ios中会有不同的展示效果,主要也是展示在webkit内核中,以及android和ios中 大概是说字体渲染的 ...