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 ...
随机推荐
- day15-函数进阶
1.函数嵌套 多个函数嵌套在一起即为函数嵌套 在调用函数时,函数需在调用之前定义,如果函数在调用之后才定义,则不能被成功调用.当定义多个函数时,函数名称不能相同,否则后定义的函数会将之前的函数覆盖,即 ...
- Delphi与各数据库数据类型比较
Delphi数据类型与各数据库数据类型对比如下表,如有具体说明见表中脚注: Delphi Type Oracle Types SQL Server Types MySQL Types [1] Inte ...
- Eclipse SVN文件冲突及不能直接提交情况
下图为Eclipse SVN使用过程中存在文件冲突的情形. 以下是三种冲突情形及相应解决办法: 1.简单的文件版本冲突 情形:A改变了文件的头部,B改变了文件的尾部,如果两者改动互不影响,SVN可以智 ...
- 在WINDOWS上开发IOS应用的方法
1,虚拟机上安装MAC系统,里面装XCODE 2,WINDOWS上安装code blocks,这个IDE可以直接在WIN上编译XCODE工程: 最新的IOS在windows环境下编译环境搭建记录
- [ SHELL编程 ] shell编程中数值计算方法实例
SHELL编程中经常会涉及到数值计算,有时候对于这些计算命令使用场景容易忘记或者混淆,这里针对常用的命令做个总结.主要包括let.bc.expr.(())等. 1.let 使用格式:let 表达式,表 ...
- C++ 简单实现MFC ListControl 点击列头排序
说明: SetItemData可以为每一行绑定一个DWORD类型的变量.用GetItemData可以获得这个变量.举个例子,假设CListCtrl中你需要显示某个数据表中的记录,该表有个流水号主键ID ...
- Docker虚拟化平台
1.虚拟化技术的概念 1)虚拟化就是把物理资源转变为逻辑上可以管理的资源,以打破物理结构间的壁垒,让计算机的元件运行在虚拟的基础上,而不是真实的物理设备: 2)虚拟化技术可以将物理机硬件资源虚拟生成单 ...
- tensorflow的save和restore
使用tensorflow中的save和restore可以对模型进行保存和恢复 import tensorflow as tf v1 = tf.Variable(tf.random_normal([1, ...
- 辅助测试工具xip.io
http://xip.io/ https://github.com/basecamp/xip-pdns
- Vue sync修饰符的使用
父子组件传值,父组件可以给子组件传值,但是子组件是不能修改组件提供的值,这里vue提供了sync修饰符,以前父组件点击子组件显示,子组件关闭按钮,父组件再点击子组件就无法让子组件显示.因为子组件点击关 ...