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& ...
随机推荐
- losbyday Linux下的强大工具之一akw(转),Shell必备
简单使用:awk :对于文件中一行行的独处来执行操作 .awk -F :'{print $1,$4}' :使用‘:’来分割这一行,把这一行的第一第四个域打印出来 . 详细介绍:AWK命令介绍 a ...
- Spring--Bean scope
singleton, prototype,request, session, global session bean.xml: <?xml version="1.0" enc ...
- enum的java例子
Grade.java package com.zhiyuan.myenum; /** * <p>Title: 枚举类 * <p>Company: * @description ...
- jquery 改变变量出现值不同步
出现问题的代码 var unc = 0; $.get( 'index.php', 'data=1', function(res) { unc=1; } ); alert(nuc); 这样的话,不管aj ...
- ymodem协议c实现(转)
源:ymodem协议c实现 /****************************************Copyright (c)******************************** ...
- MUI开发注意事项
mui开发注意事项,有需要的朋友可以参考下. mui是一个高性能的HTML5开发框架,从UI到效率,都在极力追求原生体验:这个框架自身有一些规则,刚接触的同学不很熟悉,特总结本文:想了解mui更详细的 ...
- “&”详解
1.引用 引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样. &作为引用的时候,必须在定义时候就进行初始化,若不进行初始化则会编译报错. 2.取地址 &作为取地 ...
- UnitOfWork实战
企业模式之Unit Of Work模式 在开始UnitOfWork模式之前有必要回顾下我们耳熟能详的Data Access Object(DAO)模式,即数据访问对象.DAO是一种简单的模式,我们构建 ...
- 实时 Django 终于来了 —— Django Channels 入门指南
Reference: http://www.oschina.net/translate/in_deep_with_django_channels_the_future_of_real_time_app ...
- 微信网页授权redirect_uri错误的可能错误之一
授权回调页面域名 后面不要加/ 加了/ 就会出错.