TZOJ 2999 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.
输入
The input 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.
输出
The output contains for each block except the last in the input one line containing the number of critical places.
样例输入
5
5 1 2 3 4
0
6
2 1 3
5 4 6 2
0
0
样例输出
1
2
题意
求连通图关键点数量,关键点为去掉该点图不连通
题解
直接求割点数量
代码
#include<bits/stdc++.h>
using namespace std; const int N=1e5+; vector<int>G[N];
int dfn[N],low[N],tot;
bool cut[N];
void tarjan(int u,int fa)
{
int child=;
dfn[u]=low[u]=++tot;
for(int i=;i<G[u].size();i++)
{
int v=G[u][i];
if(!dfn[v])
{
tarjan(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]&&u!=fa)cut[u]=true;
if(u==fa)child++;
}
low[u]=min(low[u],dfn[v]);
}
if(u==fa&&child>=)cut[u]=true;
}
void init(int n)
{
tot=;
for(int i=;i<=n;i++)
{
G[i].clear();
dfn[i]=low[i]=;
cut[i]=false;
}
}
int main()
{
int n,u,v;
while(~scanf("%d",&n)&&n)
{
init(n);
while(~scanf("%d",&u)&&u)
{
while(getchar()!='\n')
{
scanf("%d",&v);
G[u].push_back(v);
G[v].push_back(u);
}
}
tarjan(,);
int ans=;
for(int i=;i<=n;i++)if(cut[i])ans++;
printf("%d\n",ans);
}
return ;
}
TZOJ 2999 Network(连通图割点数量)的更多相关文章
- TZOJ 2018 SPF(连通图割点和分成的连通块)
描述 Consider the two networks shown below. Assuming that data moves around these networks only betwee ...
- UVA315 Network 连通图割点
题目大意:有向图求割点 题目思路: 一个点u为割点时当且仅当满足两个两个条件之一: 1.该点为根节点且至少有两个子节点 2.u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的 ...
- POJ1144 Network 题解 点双连通分量(求割点数量)
题目链接:http://poj.org/problem?id=1144 题目大意:给以一个无向图,求割点数量. 这道题目的输入和我们一般见到的不太一样. 它首先输入 \(N\)(\(\lt 100\) ...
- TZOJ 2546 Electricity(去掉割点后形成的最大连通图数)
描述 Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The compa ...
- uva-315.network(连通图的割点)
本题大意:求一个无向图额割点的个数. 本题思路:建图之后打一遍模板. /**************************************************************** ...
- poj 1144 (Tarjan求割点数量)
题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...
- POJ1144 Network(割点)题解
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...
- POJ 1144 Network(割点)
Description A Telephone Line Company (TLC) is establishing a new telephone cable network. They are c ...
- POJ1144 Network 无向图割点
题目大意:求以无向图割点. 定义:在一个连通图中,如果把点v去掉,该连通图便分成了几个部分,则v是该连通图的割点. 求法:如果v是割点,如果u不是根节点,则u后接的边中存在割边(u,v),或者v-&g ...
随机推荐
- flash时间轴声音大小控制
A2时间轴声音大小控制: var sound:Sound = new Sound(); sound.setVolume(200); 把背景音乐放到一个影片剪辑里,剪辑起名 例如bgm_mc 声音模式为 ...
- idea插件JRebel 解决热编译,开启高级debug之路
idea自身的debug模式遇到 类属性增加什么的只能重启,不能做到更深层次的热部署...至于为啥不能,---这是java自身类加载机制导致的?这个问题可以以后深究(貌似很深奥)....本文的重点是介 ...
- win7下iis的配置问题
开始asp的学习时,首先得配置iis服务,中途遇到各种问题也谷歌了不少,但是答案都很凌乱,折腾了两天才彻底解决这个问题.下面是我坎坷的配置过程,希望对你有所帮助: 第一步:打开Internet信息服务 ...
- vue.js 中双向绑定的实现---初级
1. 1 我们看到的变量,其实都不是独立的,它们都是windows对象上的属性 <!DOCTYPE html> <html lang="en"> <h ...
- 数据结构:Queue
Queue设计与实现 Queue基本概念 队列是一种特殊的线性表 队列仅在线性表的两端进行操作 队头(Front):取出数据元素的一端 队尾(Rear):插入数据元素的一端 队列不允许在中间部位进行操 ...
- ReactiveX 学习笔记(12)调度器
Schedulers, threading and testing 本文的主题为调度器,多线程以及测试. RxJava操作符(六)Utility SubscribeOn / ObserveOn Sub ...
- 【386】operator 的 itemgetter、slice、and_、or_
itemgetter 用来获取数组中指定索引的元素 from operator import itemgetter itemgetter(1, 3, 5)('ABCDEFG') output: ('B ...
- Android签名
参考文档:http://blog.csdn.net/u010316858/article/details/53159678 http://www.cnblogs.com/wanqieddy/p/355 ...
- Assetbundle创建与加载
[Assetbundle创建与加载] Unity有两种动态加载机制:一种是Resource.Load.一种是AssetBundle.Assetbundle是Unity Pro提供的功能,它可以把多个游 ...
- Mysql字段类型与合理选择
字段类型 数值 MySQL 的数值数据类型可以大致划分为两个类别,一个是整数,另一个是浮点数或小数.许多不同的子类型对这些类别中的每一个都是可用的,每个子类型支持不同大小的数据,并且 MySQL 允许 ...