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);
}
}

POJ 1144 Network(割点)的更多相关文章

  1. poj 1144 Network(割点)

    题目链接: http://poj.org/problem?id=1144 思路分析:该问题要求求出无向联通图中的割点数目,使用Tarjan算法即可求出无向联通图中的所有的割点,算法复杂度为O(|V| ...

  2. poj 1144 Network(割点 入门)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10907   Accepted: 5042 Descript ...

  3. POJ 1144 Network(无向图连通分量求割点)

    题目地址:id=1144">POJ 1144 求割点.推断一个点是否是割点有两种推断情况: 假设u为割点,当且仅当满足以下的1条 1.假设u为树根,那么u必须有多于1棵子树 2.假设u ...

  4. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  5. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  6. poj 1144 Network(无向图求割顶数)

    题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...

  7. poj 1144 Network 【求一个网络的割点的个数 矩阵建图+模板应用】

    题目地址:http://poj.org/problem?id=1144 题目:输入一个n,代表有n个节点(如果n==0就结束程序运行). 在当下n的这一组数据,可能会有若干行数据,每行先输入一个节点a ...

  8. poj 1144 Network【双连通分量求割点总数】

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11042   Accepted: 5100 Descript ...

  9. POJ 1144 Network(tarjan 求割点个数)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17016   Accepted: 7635 Descript ...

  10. poj 1144 Network 无向图求割点

    Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...

随机推荐

  1. git submodule update --init --recursive

    最近在跑好几个模型,视频检测,物体检测,搭建mxnet时,有点问题,记录一下. 视频检测,mxnet需要用指定版本,git 切换到指定版本后,update了,但是依然提示说有些库找不到.想了想,应该是 ...

  2. 整理下react中常见的坑

    其实有些也不能算是坑,有些是react的规定,或者是react的模式和平常的js处理的方式不同罢了 1.setState()是异步的this.setState()会调用render方法,但并不会立即改 ...

  3. Oracle树形结构数据---常见处理情景

    Oracle树形结构数据---常见处理情景 1.查看表数据结构 SELECT *      FROM QIANCODE.TREE_HIS_TABLE T  ORDER BY T.NODE_LEVEL; ...

  4. iOS 获取APP的CPU、内存等信息

    目标是开发一个SDK,嵌入到APP里面,用来统计当前APP的实时CPU.内存等信息 2015.11.17 http://stackoverflow.com/questions/12889422/ios ...

  5. SQLSERVER SQL性能优化

      1.选择最有效率的表名顺序(只在基于规则的优化器中有效)      SQLSERVER的解析器按照从右到左的顺序处理FROM子句中的表名,因此FROM子句中写在最后的表(基础表driving ta ...

  6. rest_framework --- viewsets

    viewsets :from rest_framework import viewsets #导入方式 ViewSetMixin(object): 这个类,大致作用就是重写了as_view()方法,假 ...

  7. date 参数(option)-d

    记录这篇博客的原因是:鸟哥的linux教程中,关于date命令的部分缺少-d这个参数的介绍,并且12章中的shell编写部分有用到-d参数 date 参数(option)-d与--date=" ...

  8. 新知识 HtMl 5

    快要毕业了,即将走向实习岗位,但是这日子过的太无聊了,昨天逃课回宿舍打开电脑想看电影但是没什么好看的,于是上床睡觉了,越躺越无聊,然后爬了起来到学习图书馆找了本HTML5的课本,学习了起来(我感觉ht ...

  9. scrapy爬取伯乐在线文章数据

    创建项目 切换到ArticleSpider目录下创建爬虫文件 设置settings.py爬虫协议为False 编写启动爬虫文件main.py

  10. powerpoint教程资料,PPT的

    Powerpoint,是微软公司设计的演示文稿软件,利用Powerpoint不仅可以创建演示文稿,还可以在互联网上召开面对面会议.远程会议或在网上给观众展示演示文稿,掌握利用PowerPoint是一项 ...