POJ 1144 Network(割点)
2024-09-07 07:54:31
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);
}
}
最新文章
- WPF Tookit Chart
- codecademy-command line_filesystem
- EMV技术学习和研究(转)
- Apache安全配置
- Spring笔记——Spring+JDBC组合开发
- C#打开mdb文件,获取文件下的所有表格,以及获取表格下的所有字段
- c++ string 拼接 int错误
- C# 保存PictureBox中的图片到数据库,并从数据库读取图片显示到PictrueBox,解决报错 “无效参数”
- 写给新入IT的新人们
- ios 实时刷新屏幕
- 关于LD_DEBUG (转载)
- javascript之定义函数时 this 和prototype区别
- 操作IFRAME及元素
- Linux CentOS7.0 (03)安装验证 docker
- java 多线程简单例子
- JavaI/O(输入/输出)
- shell常用符号的意义
- python练习题:三级菜单
- PreparedStatement插入values
- MVC下载文档