POJ1144(割点)
Network
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 12551 | Accepted: 5771 |
Description
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
by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;
Output
Sample Input
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
Sample Output
1
2
Hint
//2016.9.16
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 105 using namespace std; int n, root, book[N], edge[N][N], num[N], low[N], Index;
//book用来记录哪些点是割点,edge以邻接矩阵保存图,num[i]为顶点i的时间戳,low[i]为顶点i不经过父顶点所能回到的最小时间戳 void dfs(int cur, int fa)
{
int child = ;
Index++;
num[cur] = low[cur] = Index;
for(int i = ; i <= n; i++)
{
if(edge[cur][i]==)
{
if(num[i] == )
{
child++;
dfs(i, cur);
low[cur] = min(low[cur], low[i]);
if(cur!=root && low[i]>=num[cur])
book[cur] = ;
if(cur==root && child==)
book[cur] = ;
}else if(i != fa)
{
low[cur] = min(low[cur], num[i]);
}
}
}
return;
} int main()
{
int u, v;
while(scanf("%d", &n) && n)
{
memset(edge, , sizeof(edge));
memset(low, , sizeof(low));
memset(num, , sizeof(num));
memset(book, , sizeof(book));
Index = ; root = ;
while(scanf("%d", &u) && u)
{
while(getchar() != '\n')
{
scanf("%d", &v);
edge[u][v] = ;
edge[v][u] = ;
}
}
dfs(, root);
int cnt = ;
for(int i = ; i <= n; i++)
if(book[i])cnt++;
printf("%d\n", cnt);
} return ;
}
POJ1144(割点)的更多相关文章
- POJ1144(割点入门题)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11378 Accepted: 5285 Descript ...
- [POJ1144][BZOJ2730]tarjan求割点
求割点 一种显然的n^2做法: 枚举每个点,去掉该点连出的边,然后判断整个图是否联通 用tarjan求割点: 分情况讨论 如果是root的话,其为割点当且仅当下方有两棵及以上的子树 其他情况 设当前节 ...
- poj1144 tarjan求割点
poj1144 tarjan求割点 额,算法没什么好说的,只是这道题的读入非常恶心. 注意,当前点x是否是割点,与low[x]无关,只和low[son]和dfn[x]有关. 还有,默代码的时候记住分目 ...
- poj1144 求不同割点的个数
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11914 Accepted: 5519 Descript ...
- poj1144 Network【tarjan求割点】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4319585.html ---by 墨染之樱花 [题目链接]http://poj.org/p ...
- POJ1144 Network(割点)题解
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...
- (连通图 模板题 无向图求割点)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& ...
随机推荐
- Extjs4---Cannot read property 'addCls' of null - heirenheiren的专栏 - 博客频道 - CSDN.NET
body { font-family: 微软雅黑,"Microsoft YaHei", Georgia,Helvetica,Arial,sans-serif,宋体, PMingLi ...
- codeforce 611A New Year and Days
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- 关于textarea的应用--onchage,onpropertychange,oninput
oninput,onpropertychange,onchange的用法 1.onchange触发事件必须满足两个条件: a)当前对象属性改变,并且是由键盘或鼠标事件激发的(脚本触发无效) b)当前对 ...
- ecos的app包管理
install 安装 install app_name1 app_name2 有时候要用-o参数,把所有安装过程需要的参数带入进去(安装过程的参数放在app/$app_name/task.php里in ...
- eclipse创建android项目,无法正常预览布局文件
http://jingyan.baidu.com/article/d621e8da0e0e052865913fae.html
- git使用系列(一)
git commit 的时候出现了问题: change not staged for commit. no changes added to commit(use "git add" ...
- Spring MVC 程序首页的设置 - 一号门-程序员的工作,程序员的生活(java,python,delphi实战)
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- HDU 5613 Baby Ming and Binary image
因为第一行和最后一行都是0,我们只需枚举最左边或最右边一列的01情况,即可得到整张表 然后再检验表是否符合要求 #include<cstdio> #include<cstring&g ...
- sublime C++ build system配置体验
近期准备实习,于是终于步入了sublime的阵营,sublime确实性感. 在配置win7下C++编译运行集成环境的时候遇到点问题,于是接触了一下JSON格式,最后终于自己搞定了.. 参考文档:htt ...
- 基于LNMP的Zabbbix之PHP源码安装
安装一些依赖的包 wget -c ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz .tar.gz -C ../source/ cd ../source/l ...