B - Network---UVA 315(无向图求割点)
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.
Sample Input
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
Sample Output
1
2
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=251
题意:有n个电话,有一些线连接在他们之间,有的电话如果不能工作了,则可能导致,n个电话不连通了,求出这样的电话又几个,其实就是求割点有多少个
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define maxn 10005
int dfn[maxn];///代表最先遍历到这个点的时间
int low[maxn];///这个点所能到达之前最早的时间点
int Father[maxn];///保存这个节点的父亲节点
int n, m, Time, top;///Time 时间点, top用于栈操作
vector<vector<int> > G; void Init()
{
G.clear();
G.resize(n+1);
memset(low, 0, sizeof(low));
memset(dfn, 0, sizeof(dfn));
memset(Father, 0, sizeof(Father));
Time = 0;
} void Tarjan(int u,int fa)
{
low[u] = dfn[u] = ++Time;
Father[u] = fa;
int len = G[u].size(), v; for(int i=0; i<len; i++)
{
v = G[u][i]; if(!dfn[v])
{
Tarjan(v, u);
low[u] = min(low[u], low[v]);
}
else if(fa != v)///假如我们在这里写上了 low[u] = min(low[v], low[u]),那么就相当于我们由v回到了v之前的节点
low[u] = min(dfn[v], low[u]);
}
}
void solve()
{/**
求割点
一个顶点u是割点,当且仅当满足(1)或(2)
(1) u为树根,且u有多于一个子树。
(2) u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的父亲),使得 dfn(u)<=low(v)。
(也就是说 V 没办法绕过 u 点到达比 u dfn要小的点)
注:这里所说的树是指,DFS下的搜索树*/
int RootSon = 0, ans = 0;///根节点儿子的数量
bool Cut[maxn] = {false};///标记数组,判断这个点是否是割点 Tarjan(1,0); for(int i=2; i<=n; i++)
{
int v = Father[i];
if(v == 1)///也是就说 i的父亲是根节点
RootSon ++;
else if(dfn[v] <= low[i])
Cut[v] = true;
} for(int i=2; i<=n; i++)
{
if(Cut[i])
ans ++;
}
if(RootSon > 1)
ans++; printf("%d\n", ans);
}
int main()
{
while(scanf("%d", &n), n)
{
int a, b;
char ch;
Init();
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;
}
}
solve();
}
return 0;
}
B - Network---UVA 315(无向图求割点)的更多相关文章
- B - Network - uva 315(求割点)
题意:给一个无向连通图,求出割点的数量. 首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第一个数字代表后面的都和它存在边,0表示行输入的结束(很蛋疼的输入方式). 分析:割点的模板题 ...
- Network UVA - 315 无向图找割点
题意: 给你一个无向图,你需要找出来其中有几个割点 割点/割项: 1.u不为搜索起点,low[v]>=dfn[u] 2.u为搜索起点,size[ch]>=2 3.一般情况下,不建议在tar ...
- Network UVA - 315(求割点)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- UVA 315 Network (模板题)(无向图求割点)
<题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...
- uva 315 Network(无向图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 无向图求割点 UVA 315 Network
输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #in ...
- poj 1144 Network 无向图求割点
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- kuangbin专题 专题九 连通图 Network UVA - 315
题目链接:https://vjudge.net/problem/UVA-315 题目:求割点. #include <iostream> #include <cstdio> #i ...
随机推荐
- Linux基础知识之history的详细说明
背景:history是Linux中常会用到内容,在工作中一些用户会突然发现其安装不了某个软件,于是寻求运维人员的帮助,而不给你说明他到底做了哪些坑爹的操作.此时你第一件要做的就是要查看其history ...
- 关于C++中using namespace std
原文链接:http://www.kuqin.com/language/20080107/3532.html <iostream>和<iostream.h>是不一样,前者没有后缀 ...
- 动态调用WCF不添加服务(svcutil.exe)
记录下 首先用svcutil.exe把指定wcf接口的信息下载下来. 生成代理类 比如说接口地址为 http://localhost:6666/Service1.svc 以管理员身份打开cmd 执形 ...
- HttpClient三种不同的服务器认证客户端方案
http://blog.csdn.net/i_lovefish/article/details/9816783 HttpClient三种不同的认证方案: Basic, Digest and NTLM. ...
- linux下如何关闭防火墙、查看当前的状态、开放端口
从配置菜单关闭防火墙是不起作用的,索性在安装的时候就不要装防火墙查看防火墙状态:/etc/init.d/iptables status暂时关闭防火墙:/etc/init.d/iptables stop ...
- 阿里巴巴CI/CD之分层自动化
一佛是阿里巴巴B2B事业群高级产品经理.从事多年互联网系统的研发和测试工作,目前主要负责云效分层自动化测试的产品设计.因为自动化测试在实践过程中,总是碰到各种各样的问题,导致进入自动化测试盲区.所以, ...
- NHibernate初学三之条件查询(Criteria Queries)与AspNetPager分页实例
NHibernate除了SQL与HQL两种查询操作外,还有一种就是条件查询Criteria,本文将从网上整理一些Criteria的理论及小实例,最后通过一个结合AspNetPager分页来加深理解,必 ...
- C#设计模式系列:抽象工厂模式(AbstractFactory)
出自:http://www.cnblogs.com/libingql/archive/2012/12/09/2809754.html 1. 抽象工厂模式简介 1.1 定义 抽象工厂(Abstract ...
- 超全面的JavaWeb笔记day22<文件上传>
文件上传概述 1 文件上传的作用 例如网络硬盘!就是用来上传下载文件的. 在智联招聘上填写一个完整的简历还需要上传照片呢. 2 文件上传对页面的要求 上传文件的要求比较多,需要记一下: 1. 必须使用 ...
- testNG框架提示:Cannot find class in classpath: NewTest
selenium+Java的testNG运行时,报如下错误: org.testng.TestNGException: Cannot find class in classpath: NewTest a ...