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> ...
随机推荐
- BZOJ3110:[ZJOI2013]K大数查询——题解
+++++++++++++++++++++++++++++++++++++++++++ +本文作者:luyouqi233. + +欢迎访问我的博客:http://www.cnblogs.com/luy ...
- LUOGU 1440
#include<cstdio> #include<algorithm> #include<cstring> #define N 1000005 using nam ...
- mybatis生成的pojo 中的属性或方法不够我们当做dto使用时
我们在写代码的时候,如果一个 mybatis生成的pojo 中的属性或方法不够我们使用(当做dto和前台交互)时,我们有两种方法: 第一: 直接在 原 pojo 中增加属性或者方法 第二:我们可以再写 ...
- httpclient post请求带参数返回数据乱码问题解决
客户端代码: //带参数的post请求 @Test public void doPostWithParam() throws Exception { CloseableHttpClient httpC ...
- 洛谷:P2922 [USACO08DEC]秘密消息(Trie树)
P2922 [USACO08DEC]秘密消息Secret Message 题目链接:https://www.luogu.org/problemnew/show/P2922 题目描述 贝茜正在领导奶牛们 ...
- [net tools]nethogs
nethogs 按照从大到小排列占用网络流量的进程 还可以用jnettop察看,总的流量
- Getting Private/Public IP address of EC2 instance using AWS-cli [closed]
For private IP address: aws ec2 describe-instances --instance-ids i-b78a096f | grep PrivateIpAddress ...
- 仿微信中加载网页时带线行进度条的WebView的实现
finddreams:http://blog.csdn.net/finddreams/article/details/44172639 为了仿微信中加载网页时带进度条的WebView的实现,首先我们来 ...
- Java 中 给静态方法 添加泛型 (static <T>)
今天在用到static方法的时候.想要用泛型.结果不能通过编译. 上网查了一下.其具体写法如下:
- py_faster_rcnn识别出来的结果好多红框重叠
py_faster_rcnn识别出来的结果好多红框重叠, 可以通过调节demo.py中的NMS_THRESH的值进行限制. NMS_THRESH表示非极大值抑制,这个值越小表示要求的红框重叠度越小,0 ...