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

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.

//题意,给一个图,求图中割顶的个数~~~

#include "stdio.h"  //poj 1144 割顶的判断模板
#include "vector"
#include "string.h"
using namespace std; #define N 105
vector<int> a[N];
int root;
int low[N],dfn[N];
bool visit[N],mark[N];
int MIN(int x,int y) { return x<y?x:y; } void DFS(int x,int times)
{
int i;
int count = 0;
visit[x] = true;
low[x] = dfn[x] = times;
for(i=0; i<a[x].size(); ++i)
{
int y = a[x][i];
if(!visit[y])
{
count++;
DFS(y,times+1);
low[x] = MIN(low[x],low[y]);
if(x==root && count==2) mark[root] = true; //如果x为根节点,并且子树有两个或两个以上,则为割顶!
if(x!=root && low[y]>=dfn[x]) mark[x] = true; //如果x的子树中没有节点连接x的祖先(有的话low[x]会变小),则为割顶!
}
else
low[x] = MIN(low[x],dfn[y]);//更新low[x]的值!
}
} int main()
{
int n;
int i,j;
char ch;
while(scanf("%d",&n),n!=0)
{
int x,y;
for(i=0; i<N; ++i)
a[i].clear();
while(scanf("%d",&x),x!=0)
{
while(scanf("%c",&ch) && ch==' ')
{
scanf("%d",&y);
a[y].push_back(x);
a[x].push_back(y);
}
}
root = 1;
int times = 1;
memset(mark,false,sizeof(mark)); //标记点是否是割顶
memset(visit,false,sizeof(visit)); //标记点是否已访问 DFS(root,times);
int ans = 0;
for(i=1; i<=n; ++i)
{
if(mark[i]) ans++; //统计割顶个数
}
printf("%d\n",ans);
}
return 0;
}

poj 1144 Network 图的割顶判断模板的更多相关文章

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

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

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

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

  3. 图论(无向图的割顶):POJ 1144 Network

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

  4. POJ 1144 Network【割顶】

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

  5. POJ 1144 Network(Tarjan求割点)

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

  6. POJ1144 Network 无向图的割顶

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

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

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

  8. POJ 1144 Network (求割点)

    题意: 给定一幅无向图, 求出图的割点. 割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html 分析: 输入有点麻烦, 用stringsteam 会比较 ...

  9. poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】

    题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...

随机推荐

  1. 【WP8】扩展CM的WindowManager

    14-09-09更新:修复AppBar冲突bug 关于WindowManager,一直都很想写一篇博客分享一下,一直在忙别的,今天抽空把这个分享一下 在弹窗在移动开发是一个很常见的交互,很多时候我们都 ...

  2. Python基础:数值(布尔型、整型、长整型、浮点型、复数)

    一.概述 Python中的 数值类型(Numeric Types)共有5种:布尔型(bool).整型(int).长整型(long).浮点型(float)和复数(complex). 数值类型支持的主要操 ...

  3. ASP.NET MVC4 传递Model到View

    原文发表在:http://www.star110.com/Note/ReadArticle/60641215331146140043.html 开发环境:.NET MVC4 + EF6.0 模型: 1 ...

  4. 使用EasyUI的插件前需要引入的文件

    一.使用EasyUI的插件需要引入一些文件 1.引入相关文件 easyui.css: easyUi的样式文件 icon.css:easyUI的图标样式文件 easyui.min.js:easyUi的类 ...

  5. 通过发布项目到IIS上,登录访问报系统找不到System.Web.Mvc

    我发布项目到IIs,通过IIS的端口来访问直接下面的错误

  6. HDU 2159---FATE---带限制的完全背包

    HDU   2159 Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务.久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一 ...

  7. 容器--Collection和AbstractCollection

    一.前言 容器是JAVA中比较重要的一块,整个体系设计得非常好,同时对于代码学习来说也是比较好的范例.同时很多面试官也比较喜欢用容器来考察面试者的基础知识,所以掌握好容器还是比较重要的.本文主要总结一 ...

  8. Linux Shell系列教程之(十二)Shell until循环

    本文是Linux Shell系列教程的第(十二)篇,更多Linux Shell教程请看:Linux Shell系列教程 在上两篇文章Linux Shell系列教程之(十)Shell for循环和Lin ...

  9. 我所了解的WEB开发(3) - 彩虹的颜色

    据说彩虹有七彩颜色,从外至内分别为:红.橙.黄.绿.青.蓝.紫.这些我倒是没有验证过,但是学生时代就不止一次色盲检测,还是让我足够确信对颜色的分辨应该和大多数人相似的. 还听说大多数哺乳动物是色盲.如 ...

  10. winform(ListView及数据库连接)

    一.ListView:列表展示数据1.视图 - 在其右上方小箭头点击将视图改为Largelcon:或右键属性在外观View将其改为Details2.设置列头 - 在其右上方小箭头点击选择编辑列,然后添 ...