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& ...
随机推荐
- Counting Intersections
Counting Intersections Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- Android Camera 调用流程总结
1.总体介绍 Android Camera框架从整体上看是一个client/service架构.有两个进程,一个是client进程,可以看成AP端,主要包括Java代码和一些native层的c/c+ ...
- (简单) POJ 3074 Sudoku, DLX+精确覆盖。
Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgr ...
- ZOJ 3537 Cake
区间DP. 首先求凸包判断是否为凸多边形. 如果是凸多边形:假设现在要切割连续的一段点,最外面两个一定是要切一刀的,内部怎么切达到最优解就是求子区间最优解,因此可以区间DP. #include< ...
- 使用DLL进行不同语言之间的调用(转)
源:使用DLL进行不同语言之间的调用 __declspec(dllexport) 是告诉编译器用来导出函数的,在代码中不另作说明了. extern "C" 的意思就是用C的方式来导 ...
- RabbitMQ java 参数
channel.exchangeDeclare(exchange, "direct", true, false, null); 第一个参数:交换组名字, 第二个参数:队交换组类型: ...
- unicode转GBK,GNK转unicode,解决FATFS中文码表占用ROM问题(转)
源:unicode转GBK,GNK转unicode,解决FATFS中文码表占用ROM问题 之前一直使用的512KB ROM的STM32,但是最近使用的只有128KB,想用FATFS显示支持长文件名,发 ...
- 【转】25个Git用法技巧
Andy Jeffries 给 Git 中级用户总结分享的 25 个小贴士.你不需要去做大量搜索,或许这些小贴士对你就很有帮助的. 我从开始使用git到现在已经差不多18个月了,以为自己已经很懂git ...
- linux 更换yum源
1.进入存放源配置的文件夹 cd /etc/yum.repos.d 2.备份默认源 mv ./CentOS-Base.repo ./CentOS-Base.repo.bak 3.使用wget下载163 ...
- C语言-for循环
for循环是C语言中的循环语句之一,它的一般形式为for(初值,条件表达式,步长){语句};初值通常是一个赋值语句, 它用来给循环控制变量赋初值: 条件表达式是一个关系表达式, 它决定什么时候退出循环 ...