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. SpringBoot集成Kafka的实战用法大全

    本文是SpringBoot+Kafka的实战讲解,如果对kafka的架构原理还不了解的读者,建议先看一下<大白话kafka架构原理>.<秒懂kafka HA(高可用)>两篇文章 ...

  2. Shell 统计文件的行数

    目录 统计文件的行数 题目 题解-awk 题解-wc 题解sed 统计文件的行数 题目 写一个 bash脚本以输出一个文本文件 nowcoder.txt中的行数 示例: 假设 nowcoder.txt ...

  3. 零基础学习java------30---------wordCount案例(涉及到第三种多线程callable)

    知识补充:多线程的第三种方式 来源:http://www.threadworld.cn/archives/39.html 创建线程的两种方式,一种是直接继承Thread,另外一种就是实现Runnabl ...

  4. 【STM8】外挂存储器W25Q16

    好像有几张图片被强制缩小了?看到这篇博客的人先对你们说声抱歉,我不知道怎么设置 文字就可以很长(文章宽度的全部),图片就只有文章宽度的2/3宽度 开新分页应该就是原始尺寸了,这点还是和大家说抱歉... ...

  5. Android给页面添加横线和竖线

    竖线 <View      android:layout_width="1dip"     android:layout_height="match_parent& ...

  6. CentOS6设置Django开发环境

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

  7. 如何用shell脚本分析网站日志统计PV、404、500等数据

    以下shell脚本能统计出网站的总访问量,以及404,500出现的次数.统计出来后,可以结合监控宝来进行记录,进而可以看出网站访问量是否异常,是否存在攻击.还可以根据查看500出现的次数,进而判断网站 ...

  8. html如何让input number类型的标签不产生上下加减的按钮(转)

    添加css代码: <style> input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit- ...

  9. 使用 scipy.fft 进行Fourier Transform:Python 信号处理

    摘要:Fourier transform 是一个强大的概念,用于各种领域,从纯数学到音频工程甚至金融. 本文分享自华为云社区<使用 scipy.fft 进行Fourier Transform:P ...

  10. input type="file"多图片上传

    单个的input type="file"表单也是可以实现多图片上传的 代码如下: <form action="manypic.php" method=&q ...