Network -UVa315(连通图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=251
Network |
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 mostN 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.
Sample Input
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
Sample Output
1
2 割点:
1.如果是头节点有大于等于1个子节点,那么他就是割点。
2.如果满足low[v]>=dfn[fa[v]],那么这个点的父节点 也就是fa[v]就是割点。
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector> using namespace std;
#define N 200 int low[N],dfn[N],n,fa[N],Stack[N];
int Time,top,ans[N];
vector<vector <int> >G; void Inn()
{
G.clear();
G.resize(n+);
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(fa,,sizeof(fa));
memset(ans,,sizeof(ans));
memset(Stack,,sizeof(Stack));
Time=top=;
} void Tarjin(int u,int f)
{
low[u]=dfn[u]=++Time;
Stack[top++]=u;
fa[u]=f;
int len, v;
len=G[u].size();
for(int i=;i<len;i++)
{
v=G[u][i];
if(!dfn[v])
{
Tarjin(v,u);
low[u]=min(low[u],low[v]);
}
else if(f!=v)
low[u]=min(low[u],dfn[v]);
}
} void slove()
{
Tarjin(,);
int num=,sum=;
for(int i=;i<=n;i++)
{
int v=fa[i];
if(v==)
num++;
else if(dfn[v]<=low[i])
ans[v]=;
}
for(int i=;i<=n;i++)
{
if(ans[i]==)
sum++;
}
if(num>)
sum++;
printf("%d\n",sum);
} int main()
{
int a,b;
char ch;
while(scanf("%d",&n),n)
{
Inn();
while(scanf("%d",&a),a)
{
while(scanf("%d%c",&b,&ch))
{
G[a].push_back(b);
G[b].push_back(a);
if(ch=='\n')
break;
}
}
slove();
}
return ;
}
Network -UVa315(连通图求割点)的更多相关文章
- [UVA315]Network(tarjan, 求割点)
题目链接: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. ...
- uva 315 Network(无向图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 无向连通图求割点(tarjan算法去掉改割点剩下的联通分量数目)
poj2117 Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3603 Accepted: 12 ...
- POJ1523:SPF(无向连通图求割点)
题目:http://poj.org/problem?id=1523 题目解析: 注意题目输入输入,防止PE,题目就是求割点,并问割点将这个连通图分成了几个子图,算是模版题吧. #include < ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- uva315(求割点数目)
传送门:Network 题意:给出一张无向图,求割点的个数. 分析:模板裸题,直接上模板. #include <cstdio> #include <cstring> #incl ...
- POJ 1144 Network(tarjan 求割点个数)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17016 Accepted: 7635 Descript ...
- UVA - 315 Network(tarjan求割点的个数)
题目链接:https://vjudge.net/contest/67418#problem/B 题意:给一个无向连通图,求出割点的数量.首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第 ...
随机推荐
- java之java.sql.SQLException: ResultSet is from UPDATE. No Data.
问题解释:java调用存储过程的时候,查询结果不能通过ResultSet来查询,需要通过CallableStatement来查询, 比如: ResultSet rs = callableStateme ...
- 块级元素的text-align对行内元素和果冻元素(inline-block)的作用
块级元素社设置了text-align:center以后,对其直接行内元素/果冻元素.继承行内元素/果冻元素都会产生“居中效应”. <style> .test4{ text-align: c ...
- Mysql函数、语句
一:日期函数: 日期函数: SELECT CURDATE(); # 2018-07-07 SELECT CURTIME(); # 11:28:24 SELECT NOW(); # 2018-07-07 ...
- 微信小程序组件解读和分析:十、input输入框
input输入框组件说明: 本文介绍input 输入框的各种参数及特性. input输入框示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 0 ...
- IOS 中使用token机制来验证用户的安全性
登录的业务逻辑{ http:是短连接. 服务器如何判断当前用户是否登录? // 1. 如果是即时通信类:长连接. // 如何保证服务器跟客户端保持长连接状态? // ...
- 手动配置wamp环境(1)--apache安装与基本操作
Apache服务器简介: Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一. 安装apac ...
- Ubuntu14.04环境下java web运行环境搭建
1.jdk安装 将下载好的安装包上传至/home目录解压 tar -zxvf jdk-8u71-linux-x64.tar.gz 执行 vim /etc/profile 在末尾添加java环境变量(J ...
- chpasswd - 成批更新用户的口令
总览 chpasswd [-e] 描述 chpasswd 从系统的标准输入读入用户的名称和口令,并利用这些信息来更新系统上已存在的用户的口令.在没有用 -e 这个开关选项的情况下,口令将按明文的形式接 ...
- AttributeError: 'dict' object has no attribute 'encode'
首先这是一个很简单的 运行时错误: 错误分析: AttributeError:属性错误,造成这种错误的原因可能有: 你尝试访问一个不存在的属性或方法.检查一下拼写!你可以使用内建函数 dir 来列出存 ...
- 认识单文件组件.vue 文件
vuejs 自定义了一种.vue文件,可以把html, css, js 写到一个文件中,从而实现了对一个组件的封装, 一个.vue 文件就是一个单独的组件.由于.vue文件是自定义的,浏览器不认识,所 ...