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. ubuntu下的openfire安装、配置、运行

    openfire服务器              Openfire 采用Java开发,开源的实时协作(RTC)服务器基于XMPP(Jabber)协议.您可以使用它轻易的构建高效率的即时通信服务器.Op ...

  2. PHP 解决时差8小时的问题

    有时候用php echo date("Y-m-d H:i:s")的时候会发现自己的时间和系统时间有差别 这里问题一般就是因为你自己的时区和配置的时区出现了差别的原因: 解决办法有三 ...

  3. VS 创建 使用C++ 静态类库(Dll)

    创建静态类库 Walkthrough: Creating and Using a Dynamic Link Library (C++) 1:菜单栏-->File, New, Project. 2 ...

  4. Orchard路由随记(一)

    对于Orchard来说,个人以为要真正理解Orchard,必须理解其路由工作方式. 一.Orchard的自定义路由由三种类型组成 1.分发类: HubRoute:其功能是按租户筛选出当前访问租户的路由 ...

  5. NgNice项目案例

    技术构架: 服务端技术:NodeJS + Express4.x + Mongodb + Mongoose 前端技术: AngularJS1.2.x + Bootstrap3.x 源码:https:// ...

  6. 【转】 CoreGraphics QuartzCore CGContextTranslateCTM 用法

    原文:http://blog.csdn.net/sqc3375177/article/details/25708447 CoreGraphics.h 一些常用旋转常量 #define M_E 2.71 ...

  7. iOS中常用的正则表达式

    iOS常用正则表达式 正则表达式用于字符串处理.表单验证等场合,实用高效.现将一些常用的表达式收集于此,以备不时之需. 匹配中文字符的正则表达式: [\u4e00-\u9fa5]评注:匹配中文还真是个 ...

  8. topcoder算法练习3

    SRM144 DIV1 1100 point Problem Statement      NOTE: There are images in the examples section of this ...

  9. phpcms(4) V9 栏目管理

    phpcms V9框架系统后台管理之栏目管理,请参见下文的源码分析(添加栏目和修改栏目): 参照添加栏目的界面图示,便于对源代码的理解: <?php   // 文件路径:phpcms/modul ...

  10. angular 实现总价满100折扣

    <div ng-controller="CartController"> <div ng-repeat="item in items"> ...