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. JS 函数--Date()函数

    1.JavaScript没有基本的日期数据类型,所以只能显式的创建Date对象.例如:var myDate=new Date(); 2.为了创建一个存储了特定日期的,或者时间的Date对象,可以简单的 ...

  2. Entity FrameWork 增删查改的本质

    之前的文章里面已经说了,EF的增删查改.那时候的修改,删除,只能是先查询出来要修改的数据,再修改,删除...现在来一个改进版的,增删查改. 1.Add static void Add() { //1. ...

  3. 人民币大写金额转换C#方法

    方法的代码如下: /// <summary> /// 人民币大写 /// </summary> /// <param name="input"> ...

  4. 创业型互联网公司应该选择PHP, JavaEE还是.NET技术路线?

    通常JavaEE和.NET被定义为构建大型在线系统,因为其支持面向对象设计,异步通讯,MVC等都相对比较完善,而PHP通常用于构建比较轻量的业务,例如SNS服务. 因为实施速度快,工程师社区规模大,开 ...

  5. BI之SSAS完整实战教程6 -- 设计维度、细化维度上:创建维度定义特性关系

    前面我们使用过数据源向导.数据源视图向导.Cube向导来创建相应的对象. 本篇我们将学习使用维度向导来创建维度. 通过前面几个向导的学习,我们归纳一下共同点,主要分成两步 1. 使用某种对象类型的向导 ...

  6. C# ObjectCache、OutputCache缓存

    /// <summary> /// 缓存操作类 /// </summary> public class Cache { private static List<strin ...

  7. csharp: WebBrowser read baidumap

    setpoint.html: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Typ ...

  8. string.join加引号

    columnsGen = string.Join(",", modelDictionary.Keys); valueGen = modelDictionary.Values.Agg ...

  9. java基础练习[一]

    moka同学java学习笔记 package moka.hello; public class HelloWorld {     public static void main(String[] ar ...

  10. 一个SpringMVC简单Demo中出现的错误

    最近在学springmvc 一个简答的Springmvc配置包括如下步骤: 1.在 web.xml 文件中配置 DispatcherServlet (该中央控制器相当于 MVC 模式中的 C),还可以 ...