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> ...
随机推荐
- BZOJ2286:[SDOI2011]消耗战——题解
+++++++++++++++++++++++++++++++++++++++++++ +本文作者:luyouqi233. + +欢迎访问我的博客:http://www.cnblogs.com/luy ...
- UOJ117:欧拉回路——题解
http://uoj.ac/problem/117 (作为一道欧拉回路的板子题,他成功的令我学会了欧拉回路) (然而我不会背……) 就两件事: 1.无向图为欧拉图,当且仅当为连通图且所有顶点的度为偶数 ...
- Linux之SSL安全套接字20160704
使用SSL前,先有 基本的TCP套接字连接.见demo代码 SSL_library_init();//在使用OpenSSL 之前,必须进行相应的协议初始化工作 OpenSSL_add_all_algo ...
- HDU1281: 棋盘游戏(二分图匹配)
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 使用feign调用服务的时候注意的问题
服务端 rest api @RequestMapping(value = "/phone") public ResponsePhone getPhone(@RequestParam ...
- c++模板类编译错误
最近想写一个c++模板类,实现一个有向图.依据惯例,类在头文件中声明,类的实现写在源文件中.可是编译的时候出现了如下错误: undefined reference to 通过谷歌发现,这是一个很常见的 ...
- bzoj 4070 [Apio2015]雅加达的摩天楼 Dijkstra+建图
[Apio2015]雅加达的摩天楼 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 644 Solved: 238[Submit][Status][D ...
- Xamarin入门浅析
1. 安装 1) 使用标准安装流程(JDK1.6 -> Android SDK -> NDK -> Xamarin Studio -> Xamarin Visual Studi ...
- MSSQL DBcheck
--1.创建数据库. --create database MyDatabase; --删除数据库 --drop database MyDatabase; ----------------------- ...
- php中使用static方法
<?php class Char{ public static $number = 0; public static $name; function __construct($what){ se ...