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.
无向图求割顶;
模板题;
 1 #include<iostream>
2 #include<string.h>
3 #include<algorithm>
4 #include<queue>
5 #include<math.h>
6 #include<stdlib.h>
7 #include<stack>
8 #include<stdio.h>
9 #include<ctype.h>
10 #include<map>
11 #include<vector>
12 using namespace std;
13 vector<int>vec[1000];
14 char ans[10000];
15 bool flag[10000];
16 int pre[1000];
17 int low[1000];
18 int tr[1000];
19 int sizee = 0;
20 int dfs(int u,int fa);
21 int main(void)
22 {
23 int n;
24 while(scanf("%d",&n),n!=0)
25 {
26 sizee = 0;
27 int t;
28 memset(flag,0,sizeof(flag));
29 memset(pre,0,sizeof(pre));
30 memset(low,0,sizeof(low));
31 memset(tr,0,sizeof(tr));
32 for(int i = 0; i < 1000; i++)
33 vec[i].clear();
34 while(scanf("%d",&t),t!=0)
35 {
36 int i,j;
37 int id;
38 gets(ans);
39 int l = strlen(ans);
40 int sum = 0;
41 for(i = 0; i <= l; )
42 {
43 if(ans[i]>='0'&&ans[i]<='9')
44 {
45 sum = 0;
46 for(j = i; ans[j]!=' '&&ans[j]!='\0'&&j <= l; j++)
47 {
48 sum = sum*10;
49 sum+=ans[j]-'0';
50 }
51 i = j;
52 vec[t].push_back(sum);
53 vec[sum].push_back(t);
54 }
55 else i++;
56 }
57 }
58 dfs(1,-1);
59 int sum = 0;
60 for(int i = 1; i <= n; i++)
61 {
62 sum+=tr[i];
63 }
64 printf("%d\n",sum);
65 }
66 return 0;
67 }
68 int dfs(int u,int fa)
69 {
70 pre[u] = low[u] = ++sizee;
71 int child = 0;
72 for(int i = 0; i < vec[u].size(); i++)
73 {
74 int ic = vec[u][i];
75 if(!pre[ic])
76 {
77 child++;
78 int lowv = dfs(ic,u);
79 low[u] = min(low[u],lowv);
80 if(lowv >= pre[u])
81 {
82 tr[u] = 1;
83 }
84 }
85 else if(pre[ic] < pre[u]&&ic!=fa)
86 {
87 low[u] = min(low[u],pre[ic]);
88 }
89 }
90 if(fa < 0&& child == 1)tr[u] = 0;
91 return low[u];
92 }

Network (poj1144)的更多相关文章

  1. 【poj1144】 Network

    http://poj.org/problem?id=1144 (题目链接) 题意 求无向图的割点. Solution Tarjan求割点裸题.并不知道这道题的输入是什么意思,也不知道有什么意义= =, ...

  2. POJ1144 Network(割点)题解

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

  3. POJ1144 Network 无向图的割顶

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

  4. ZOJ1311, POJ1144 Network

    题目描述:TLC电话线路公司正在新建一个电话线路网络.他们将一些地方(这些地方用1到N的整数标明,任何2个地方的标号都不相同)用电话线路连接起来.这些线路是双向的,每条线路连接2个地方,并且每个地方的 ...

  5. poj1144 Network【tarjan求割点】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html   ---by 墨染之樱花 [题目链接]http://poj.org/p ...

  6. [POJ1144]Network

    来源:Central Europe 1996 思路:Tarjan求割点. 一个点$x$为割点当且仅当: 1.$x$为根结点且有两棵不相交的子树. 2.$x$不为根结点且它的子树中没有可以返回到$x$的 ...

  7. (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. POJ1144:Network(无向连通图求割点)

    题目:http://poj.org/problem?id=1144 求割点.判断一个点是否是割点有两种判断情况: 如果u为割点,当且仅当满足下面的1条 1.如果u为树根,那么u必须有多于1棵子树 2. ...

  9. [poj1144]Network(求割点模板)

    解题关键:割点模板题. #include<cstdio> #include<cstring> #include<vector> #include<stack& ...

随机推荐

  1. 在Linux下搭建nRF51822的开发烧写环境(makefile版)

    http://www.qingpingshan.com/m/view.php?aid=394836

  2. Linux基础命令---mail邮件管理程序

    mail mail是一个邮件的管理程序,可以用来发送或者接收邮件. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.   1.语法       mail  [选项] ...

  3. Advanced C++ | Conversion Operators

    In C++, the programmer abstracts real world objects using classes as concrete types. Sometimes it is ...

  4. CentOS6设置Django开发环境

    今天在我的Centos6.5机器上安装 Django 开发环境,在安装完使用 "django-admin.py startproject myapp" 创建应用的时候报了下面的错误 ...

  5. File类及常用操作方法

    import java.io.File; import java.io.IOException; public class file { public static void main(String[ ...

  6. MySQL索引及性能优化分析

    一.SQL性能下降的原因 查询语句问题,各种连接.子查询 索引失效(单值索引.复合索引) 服务器调优及各个参数设置(缓冲.线程池等) 二.索引 排好序的快速查找数据结构 1. 索引分类 单值索引 一个 ...

  7. Leetcode 78题-子集

    LeetCode 78 网上已经又很多解这题的博客了,在这只是我自己的解题思路和自己的代码: 先贴上原题: 我的思路: 我做题的喜欢在本子或别处做写几个示例,以此来总结规律:下图就是我从空数组到数组长 ...

  8. 【Git】【Gitee】通过git远程删除仓库文件

    安装Git Git安装配置-菜鸟教程 没有安装下载的,请读者自行安装下载. 启动与初步配置 配置用户名与邮箱 git config --global user.name "用户名" ...

  9. Declarative Pipeline 基础语法

    Declarative Pipeline(声明式)核心概念 核心概念用来组织pipeline的运行流程 1.pipeline :声明其内容为一个声明式的pipeline脚本 2.agent:执行节点( ...

  10. py脚本 获取当前运行服务的相关信息

    一.简介 最近在统计系统中都部署了什么服务,但服务器太多,在没有标准化之前进行整理,还是写脚本收集方便一些. 当然还是需要人工去判断整理表格,为后面标准化做准备.脚本是python2.7的,默认的ce ...