Description

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.

题目大意:给一个n个点的无向连通图,求删掉一个点后,可以使图不连通的点数。

思路:裸的求割点题。

代码(16MS):

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std; const int MAXN = ;
const int MAXE = MAXN * MAXN; int head[MAXN], ecnt;
int to[MAXE], next[MAXE];
int pre[MAXN], lowlink[MAXN], dfs_clock;
bool iscut[MAXN];
int n, m, ans; void init() {
memset(head, , sizeof(head));
memset(pre, , sizeof(pre));
memset(iscut, , sizeof(iscut));
ecnt = ;
ans = dfs_clock = ;
} void add_edge(int u, int v) {
to[ecnt] = v; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; next[ecnt] = head[v]; head[v] = ecnt++;
//printf("%d--%d\n", u, v);
} void dfs(int fa, int u) {
pre[u] = lowlink[u] = ++dfs_clock;
int child = ;
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(v == fa) continue;
if(!pre[v]) {
++child;
dfs(u, v);
lowlink[u] = min(lowlink[u], lowlink[v]);
if(pre[u] <= lowlink[v]) iscut[u] = true;
} else lowlink[u] = min(lowlink[u], pre[v]);
}
if(fa < && child == ) iscut[u] = false;
} char s[ * MAXN], *p, *prev; int get_int(char *&src) {
while(!isdigit(*src) && *src) ++src;
int ret = ;
while(isdigit(*src)) ret = ret * + *src++ - '';
return ret;
} int main() {
while(scanf("%d", &n) != EOF && n) {
init();
int u, v;
while(gets(s) && *s != '') {
p = s;
u = get_int(p);
while((v = get_int(p)) > ) add_edge(u, v);
}
dfs(-, );
for(int i = ; i <= n; ++i) ans += iscut[i];
printf("%d\n", ans);
}
}

最新文章

  1. WPF Tookit Chart
  2. codecademy-command line_filesystem
  3. EMV技术学习和研究(转)
  4. Apache安全配置
  5. Spring笔记——Spring+JDBC组合开发
  6. C#打开mdb文件,获取文件下的所有表格,以及获取表格下的所有字段
  7. c++ string 拼接 int错误
  8. C# 保存PictureBox中的图片到数据库,并从数据库读取图片显示到PictrueBox,解决报错 “无效参数”
  9. 写给新入IT的新人们
  10. ios 实时刷新屏幕
  11. 关于LD_DEBUG (转载)
  12. javascript之定义函数时 this 和prototype区别
  13. 操作IFRAME及元素
  14. Linux CentOS7.0 (03)安装验证 docker
  15. java 多线程简单例子
  16. JavaI/O(输入/输出)
  17. shell常用符号的意义
  18. python练习题:三级菜单
  19. PreparedStatement插入values
  20. MVC下载文档

热门文章

  1. o&#39;Reill的SVG精髓(第二版)学习笔记——第六章
  2. Linux中软件使用笔记
  3. JavaFXML实现新窗口打开
  4. 关于alert后,才能继续执行后续代码问题
  5. JVM——Java内存区域
  6. web前端总结面试问题&lt;经常遇到的手写代码&gt;
  7. 吐血分享:QQ群霸屏技术教程2017(效益篇)
  8. Linux编译移植Qt5的环境_OMAPL138平台
  9. Python学习之property
  10. python爬取豌豆荚中的详细信息并存储到SQL Server中