B - Network

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的更多相关文章

  1. UVA 315 求割点 模板 Tarjan

    D - D Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  2. uva 315 Network(无向图求割点)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVA 315 315 - Network(求割点个数)

     Network  A Telephone Line Company (TLC) is establishing a new telephone cable network. They are con ...

  4. Uva 315 Network 判断割点

    模板题,注意输出 #include <stdio.h> #include <string.h> #include <algorithm> #include < ...

  5. 无向图求割点 UVA 315 Network

    输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #in ...

  6. B - Network - uva 315(求割点)

    题意:给一个无向连通图,求出割点的数量. 首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第一个数字代表后面的都和它存在边,0表示行输入的结束(很蛋疼的输入方式). 分析:割点的模板题 ...

  7. hrbustoj 1494(原题UVA 315 Network) 解题报告 tarjan求割点

    主要思路:使用tarjan选取一个根节点建立一个棵搜索树,判断一个点是割点的充分必要条件是,对于一个节点u如果他的孩子节点v的low值大于等于u的出生日期dfn值,进行下一步判断,如果u是我们选的根节 ...

  8. UVA 315 Network (模板题)(无向图求割点)

    <题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...

  9. Network UVA - 315(求割点)

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

随机推荐

  1. POJ. 1005 I Think I Need a Houseboat(水 )

    POJ. 1005 I Think I Need a Houseboat(水 ) 代码总览 #include <cstdio> #include <cstring> #incl ...

  2. 史上最全Linux提权后获取敏感信息方法

    http://www.freebuf.com/articles/system/23993.html 在本文开始之前,我想指出我不是专家.据我所知,在这个庞大的区域,没有一个“神奇”的答案.分享,共享( ...

  3. sshSSH Secure Shell Client root用户无法登录解决办法

    最近使用这个工具,普通用户可以登录root用户不可以登录.将vi /etc/ssh/sshd_config按照下述配置解决问题 修改sshd配置文件:vi /etc/ssh/sshd_config P ...

  4. Base class does not contain a constructor that takes '0' argument

    刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...

  5. centos6.5 配置mongodb3

    下载地址 http://www.mongodb.org/downloads 下载 curl -O -L https://fastdl.mongodb.org/linux/mongodb-linux-i ...

  6. 关于微信内置浏览器安卓端session丢失问题

    项目上线测试,发现微信安卓端存在用户登录无法验证session情况, 导致每次接口请求都无法识别,而苹果客户端不会出现此问题,非微信环境打开不会出现此问题,找到一些解决方案做下记录: 方案1: 由于微 ...

  7. LightOJ 1218 概率水题(几何分布)

    题意:给你一个n面骰子,问你投出所有面需要的次数的期望值是多少. 题解:放在过去估计秒解,结果现在自己想好久,还查了下,有人用极限证明...实际上仔细想想这种情况投出与前面不一样的概率p的倒数就是次数 ...

  8. [Luogu 2073] 送花

    很容易想到的平衡树,加个维护区间和. 只需要插入和删除操作即可. kth其实都不用的,最小和最大可以从根节点log n一直向左/一直向右跑到叶子节点而求得. 记得每插入完一个点一定要更新区间和!!更新 ...

  9. Windows下自动解压windows share上的文件

    rem mkdir c:\buildmd c:\build rem Mount the Windows share to Z drivenet use x: \\172.16.10.240\Infa_ ...

  10. Android蓝牙通信总结

    这篇文章要达到的目标: 1.介绍在Android系统上实现蓝牙通信的过程中涉及到的概念. 2.在android系统上实现蓝牙通信的步骤. 3.在代码实现上的考虑. 4.例子代码实现(手持设备和蓝牙串口 ...