UVA - 315
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description

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
/**
题意:给出一个图,让判断割点有几个
做法:Tarjan 计算割点
**/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
#define maxn 110
#define maxm 100010
struct Edge
{
int to;
int next;
bool cut;
} edge[maxm];
int head[maxn],tot;
int Low[maxn],DFN[maxn],Stack[maxn];
int Index,top;
bool Instack[maxn];
bool cut[maxn];
int add_block[maxn];
int bridge;
void addedge(int u,int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
}
void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for(int i=head[u]; i != -; i = edge[i].next)
{
v = edge[i].to;
if(v == pre) continue;
if(!DFN[v])
{
son++;
Tarjan(v,u);
if(Low[u] > Low[v]) Low[u] = Low[v];
///求桥
if(Low[v]>DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i^].cut = true;
}
///求割点
if(u!=pre && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u] ++;
}
}
else if(Low[u] > DFN[v])
{
Low[u] = DFN[v];
}
}
if(u == pre && son>) cut[u] = true;
if(u == pre)add_block[u] = son -;
Instack[u] = false;
top--;
}
void solve(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(add_block,,sizeof(add_block));
memset(cut,false,sizeof(cut));
Index = top = ;
bridge = ;
for(int i=; i<=N; i++)
{
if(!DFN[i]) Tarjan(i,i);
}
int ans = ;
for(int i=; i<=N; i++)
{
if(cut[i]) ans++;
}
printf("%d\n",ans);
}
int g[maxn][maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int n;
while(~scanf("%d",&n))
{
if(n == ) break;
int u,v;
memset(g,,sizeof(g));
while(scanf("%d",&u))
{
if(u == ) break;
while(getchar()!='\n')
{
scanf("%d",&v);
g[u][v] = g[v][u] = ;
}
}
memset(head,-,sizeof(head));
tot = ;
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
if(g[i][j])
{
addedge(i,j);
addedge(j,i);
}
}
}
solve(n);
}
return ;
}
UVA - 315的更多相关文章
- UVA 315 求割点 模板 Tarjan
D - D Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- uva 315 Network(无向图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 315 315 - Network(求割点个数)
Network A Telephone Line Company (TLC) is establishing a new telephone cable network. They are con ...
- Uva 315 Network 判断割点
模板题,注意输出 #include <stdio.h> #include <string.h> #include <algorithm> #include < ...
- 无向图求割点 UVA 315 Network
输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #in ...
- B - Network - uva 315(求割点)
题意:给一个无向连通图,求出割点的数量. 首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第一个数字代表后面的都和它存在边,0表示行输入的结束(很蛋疼的输入方式). 分析:割点的模板题 ...
- hrbustoj 1494(原题UVA 315 Network) 解题报告 tarjan求割点
主要思路:使用tarjan选取一个根节点建立一个棵搜索树,判断一个点是割点的充分必要条件是,对于一个节点u如果他的孩子节点v的low值大于等于u的出生日期dfn值,进行下一步判断,如果u是我们选的根节 ...
- UVA 315 Network (模板题)(无向图求割点)
<题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...
- Network UVA - 315(求割点)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
随机推荐
- BZOJ1591 & 洛谷2924:[USACO2008 DEC]Largest Fence 最大的围栏——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1591 https://www.luogu.org/problemnew/show/P2924#sub ...
- srtlen实现以及与sizeof的比较
这里仅为个人整理,大部分来自百科 一.strlen函数 strlen所作的仅仅是一个计数器的工作,它从内存的某个位置(可以是字符串开头,中间某个位置,甚至是某个不确定的内存区域)开始扫描,直到碰到第 ...
- PHP导出excel,无乱码
php部分 header("Content-type:application/octet-stream"); header("Accept-Ranges:bytes&qu ...
- 使用openssl实现RSA非对称加密
生成公钥私钥 使用命令生成私钥 openssl genrsa - 参数:genrsa 生成密钥 -out 输出到文件 rsa_private_key.pem 文件名 1024 长度 从私钥中提 ...
- MongoDB:删除操作
一. 根据查询条件删除文档 查询 id=1 的所有文档 test:PRIMARY> db.test_1.find({id:1}) { "_id" : ObjectId(&qu ...
- ASP.NET基础学习未整理随笔
利用新建网站添加的项目可以改完代码直接刷新就行 提交到服务程序的表单一定要具有name.<input type="hidden"value="true"n ...
- Sublime Text 配置python文件
每次配置Sublime Text的都是好一顿搜索配置信息,今天特地把自己电脑上配置好的信息保存下来,方便以后使用. 用到了 AutoPEP8.Anaconda.SublimeCodeIntel.Sub ...
- SQL Server作业没有执行的解决方法
SQL Server作业没有执行的解决方法 确保SQL Agent服务启动,并设置为自动启动,否则你的作业不会被执行 设置方法: 我的电脑--控制面板--管理工具--服务--右键 SQLSE ...
- LAMP环境介绍
LAMP简介: Lamp是一组常用于来搭建动态网站或者服务器的开源软件平台,Linux apache mysql perl或php. Linux :提供操作系统 Apache:Web服务器 Mysql ...
- mysql 修改max_connections
1.使用命令show variables 来查看当前最大连接数 show variables like '%max_connections%'; 使用命令set global max_connecti ...