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. ubuntu14.04安装samba、vpn

    前言: VPN+SAMBA,能够让你将网上申请到的VPS目录映射成自己电脑的网络驱动器,方便开发. 一.安装samba 来源:http://jingyan.baidu.com/article/00a0 ...

  2. 使用java注解的例子有没有

    使用java注解的例子 参考文档:http://www.cnblogs.com/pepcod/archive/2013/02/20/2918719.html http://www.shaoqun.co ...

  3. linq学习笔记:将List<T> 转换为 Dictionary<T Key,T Value>

    运用Linq,将List<T> 转换为 Dictionary<T Key,T Value> 即:List<T>  ToDictionary<T Key,T V ...

  4. .net RAW(16)与GUID互相转换

    .net 1.raw转guidnew guid(byte[] id);2.guid转rawGuid result;string ids = BitConverter.ToString(result.T ...

  5. 使用soapUI代替WSDL2JAVA生成cxf HTTPS 客户端调用代码

    如果直接用cxf下面的wsdl2java生成https服务调用代码,会报https证书的错误.在你不想导入证书的情况下,可以使用soapUI进行客户端代码的生成,步骤如下: 1.设置CXF,如下图: ...

  6. C++函数二义性问题,我怎么感觉编译器有偷懒嫌疑!!!

    瞎扯一段,讲得不一定对.纯属学习! struct BB{ void a(){ cout << "bb's a()\n"; }}; struct B1 : public ...

  7. 关于Asp.Net中避免用户连续多次点击按钮,重复提交表单的处理

    Web页面中经常碰到这类问题,就是客户端多次点击一个按钮或者链接,导致程序出现不可预知的麻烦. 客户就是上帝,他们也不是有意要给你的系统造成破坏,这么做的原因很大一部分是因为网络慢,点击一个操作之后, ...

  8. ubuntu 解压,压缩

    .rar解压:rar x FileName.rar压缩:rar a FileName.rar DirName

  9. Java compile时,提示 DeadCode的原因

    在工程编译时,编译器发现部分代码是无用代码,则会提示:某一行代码是DeadCode.今天compile工程的时候发现某一个循环出现这个问题,如下: public void mouseOver(fina ...

  10. 移动平台3G手机网站前端开发布局技巧汇总

    移动平台3G手机网站前端开发布局技巧汇总 作者:前端开发-武方博   发布:2011-05-10 09:11   分类:移动开发   阅读:120,618 views   7条评论     您或许正在 ...