Network (poj1144)
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.
by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
Sample Output
1
2
Hint
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)的更多相关文章
- 【poj1144】 Network
http://poj.org/problem?id=1144 (题目链接) 题意 求无向图的割点. Solution Tarjan求割点裸题.并不知道这道题的输入是什么意思,也不知道有什么意义= =, ...
- POJ1144 Network(割点)题解
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...
- POJ1144 Network 无向图的割顶
现在打算重新学习图论的一些基础算法,包括像桥,割顶,双连通分量,强连通分量这些基础算法我都打算重敲一次,因为这些量都是可以用tarjan的算法求得的,这次的割顶算是对tarjan的那一类算法的理解的再 ...
- ZOJ1311, POJ1144 Network
题目描述:TLC电话线路公司正在新建一个电话线路网络.他们将一些地方(这些地方用1到N的整数标明,任何2个地方的标号都不相同)用电话线路连接起来.这些线路是双向的,每条线路连接2个地方,并且每个地方的 ...
- poj1144 Network【tarjan求割点】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html ---by 墨染之樱花 [题目链接]http://poj.org/p ...
- [POJ1144]Network
来源:Central Europe 1996 思路:Tarjan求割点. 一个点$x$为割点当且仅当: 1.$x$为根结点且有两棵不相交的子树. 2.$x$不为根结点且它的子树中没有可以返回到$x$的 ...
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- POJ1144:Network(无向连通图求割点)
题目:http://poj.org/problem?id=1144 求割点.判断一个点是否是割点有两种判断情况: 如果u为割点,当且仅当满足下面的1条 1.如果u为树根,那么u必须有多于1棵子树 2. ...
- [poj1144]Network(求割点模板)
解题关键:割点模板题. #include<cstdio> #include<cstring> #include<vector> #include<stack& ...
随机推荐
- nordic 51822 sdk. timer 的使用
它的源代码和头文件分别为app_timer.c/app_timer.h.这是Nordic为我们提供的虚拟定时器,这个定时器不同于硬件上的TIMER,而是基于RTC1实现的一种虚拟定时器,其将定时功能作 ...
- GeckoDriver的安装和使用
GeckoDriver用于驱动Firefox,在这之前请确保已经正确安装好了Firefox浏览器并可以正常运行. 一.GeckoDriver的安装 GitHub:https://github.com/ ...
- 汇编LED实验
汇编语言点亮LED 拿到一款全新的芯片,第一个要做的事情的就是驱动其 GPIO,控制其 GPIO 输出高低电平. GPIO口是IO口的一个功能之一. 一.接下来的步骤离不开芯片手册: 1.使能所有时钟 ...
- 基于《CSAPP第九章 虚拟内存》的思考和总结
在csapp的描述中,虚拟内存的形象更加具化,虚拟内存被组织为一个由存放在磁盘上的N个连续的字节大小的单元组成的数组,内存充当了磁盘的缓存,粗呢内存的许多概念与SRAM缓存是相似的.虚拟页面有以下三种 ...
- 巩固javaweb的第二十八天
巩固内容: 设置页面的编码方式 实现代码: 每个 JSP 页面都需要设置编码方式,设置 JSP 页面的编码方式可以是下面两种方式 之一. 方式一: <%@ page contentType=&q ...
- JDBC01 获取数据库连接
概述 Java Database Connectivity(JDBC)直接访问数据库,通用的SQL数据库存取和操作的公共接口,定义访问数据库的标准java类库(java.sql,javax.sql) ...
- go 函数进阶
目录 回调函数和闭包 高阶函数示例 回调函数(sort.SliceStable) 闭包 最佳闭包实例 回调函数和闭包 当函数具备以下两种特性的时候,就可以称之为高阶函数(high order func ...
- YYYY-MM-DD引发的问题
yyyy 和 YYYY 用YYYY格式化代码 2019-12-31 转 YYYY/MM/dd 格式: 2020/12/31 2020-01-01 转 YYYY/MM/dd 格式: 2020/01/01 ...
- Linux基础命令---host域名查询工具
host host是一个常用的DNS查询工具,经常用来查询域名.检查域名解析是否正确. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora. 1.语法 ...
- gitlab之数据备份恢复
备份#备份的时候,先通知相关人员服务要听 ,停止两个服务,并影响访问 root@ubuntu:/opt/web1# gitlab-ctl stop unicorn ok: down: unicorn: ...