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. ios加载html5 audio标签用js无法自动播放

    html5 audio标签在ios 微信浏览器中是无法自动播放的,最近在做一个小的项目遇到这个问题,安卓和pc都是正常的,唯独ios不行,查阅了很多资料,找到了以下方法,也许不是最好用的方法,如果有更 ...

  2. Android WifiP2p实现

    Android WifiP2p实现 Wifi Direct功能早在Android 4.0就以经加入Android系统了,但是一直没有很好的被支持,主要原因是比较耗电而且连接并不是很稳定.但是也有很大的 ...

  3. Android 极光推送集成

    集成Jpush 1.用Android Studio创建一个Demo 2.创建激光推送开发者账号,要创建极光推送开发者帐号,请访问极光推送官方网站https://www.jiguang.cn/push ...

  4. mysql index 8.0

    创建表 use vodb; drop table if exists test1; create table test1(id int NOT NULL AUTO_INCREMENT primary ...

  5. java.util.Collections.copy()方法注意点

    今天发现单独的将一个ArrayList的对象添加到另外一个ArrayList的时候,总是源列表和目的列表相同的内存地址.原因如下: 偶然看到了Collections的copy(List desc,Li ...

  6. 【Spring Framework】Spring入门教程(五)AOP思想和动态代理

    本文主要讲解内容如下: Spring的核心之一 - AOP思想 (1) 代理模式- 动态代理 ① JDK的动态代理 (Java官方) ② CGLIB 第三方代理 AOP概述 什么是AOP(面向切面编程 ...

  7. SpringBoot中使用JUnit4(入门篇)

    添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  8. GET传参数方式

    controller:/getDetail/{id} /getDetail?id1234567 /getDetail?id=id1234567

  9. 【JS】toLocaleString 日期格式,千分位转换

    https://blog.csdn.net/Seven521m/article/details/108866881 类似于c里printf(m%)的意思 可以指定整数最少位数,小数最少与最多位数,有效 ...

  10. IOS学习路径

    iOS Developer Roadmap Start your journey today! Where Do I Start? Becoming an iOS developer is a lot ...