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& ...
随机推荐
- Redis——面试官考题
总结: 本文在一次面试的过程中讲述了 Redis 是什么,Redis 的特点和功能,Redis 缓存的使用,Redis 为什么能这么快,Redis 缓存的淘汰策略,持久化的两种方式,Redis 高可用 ...
- Linux驱动实践:如何编写【 GPIO 】设备的驱动程序?
作 者:道哥,10+年嵌入式开发老兵,专注于:C/C++.嵌入式.Linux. 关注下方公众号,回复[书籍],获取 Linux.嵌入式领域经典书籍:回复[PDF],获取所有原创文章( PDF 格式). ...
- 巩固javaweb第十天
巩固内容: HTML <meta> 元素 meta标签描述了一些基本的元数据. <meta> 标签提供了元数据.元数据也不显示在页面上,但会被浏览器解析. META 元素通常用 ...
- 日常Java 2021/10/6
声明自定义异常 class zidingyiException extends Exception{}//定义自己的异常类 单继承 public class A {} public class B ...
- 日常Java 2021/9/28
字符串反转 package m; public class m { public static void main(String[] args) { //定义一个字符串 String str = &q ...
- 机器学习常用python包
(py37) ai@ai:~$ pip freeze |grep -v '@' astor==0.8.1 certifi==2021.5.30 chardet==4.0.0 cycler==0.10. ...
- vim使用配置(转)
在终端下使用vim进行编辑时,默认情况下,编辑的界面上是没有行号的.语法高亮度显示.智能缩进等功能的. 为了更好的在vim下进行工作,需要手动配置一个配置文件: .vimrc 在启动vim时,当前用户 ...
- 解决CSV文件用Excel打开乱码问题
这篇文章适合有一定编码基础的人看,纯手动解决乱码问题请参见: 转码保存后,重新打开即可. 转码操作如下: 编辑器->另存为->ASCII码格式文件/UTF-8含BOM格式->保存. ...
- delete() and free() in C++
In C++, delete operator should only be used either for the pointers pointing to the memory allocated ...
- 【C/C++】从矩阵左上角走到右下角
tx的笔试,但是只过了10%,就离谱 #include <bits/stdc++.h> using namespace std; const int maxn = 1010; long d ...