UVA315 Network —— 割点
题目链接:https://vjudge.net/problem/UVA-315
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
题解:
模板题,求割点的个数。
注意:由于根节点没有父亲结点,所以在求割点的时候需要分开处理。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 2e18;
const int MAXN = 1e2+; struct Edge
{
int to, next;
}edge[MAXN*MAXN*];
int tot, head[MAXN]; int Index, DFN[MAXN], Low[MAXN];
bool cut[MAXN]; void addedge(int u, int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
} void Tarjan(int u, int pre)
{
DFN[u] = Low[u] = ++Index;
int son = ;
for(int i = head[u]; i!=-; i = edge[i].next)
{
int v = edge[i].to;
if(v==pre) continue;
if(!DFN[v])
{
son++;
Tarjan(v, u);
Low[u] = min(Low[u], Low[v]);
if(u!=pre && Low[v]>=DFN[u])
cut[u] = true;
}
else
Low[u] = min(Low[u], DFN[v]);
} if(u==pre && son>) cut[u] = true;
} void init()
{
tot = ;
memset(head, -, sizeof(head)); Index = ;
memset(DFN, , sizeof(DFN));
memset(Low, , sizeof(Low));
memset(cut, false, sizeof(cut));
} int main()
{
int n;
while(scanf("%d", &n) &&n)
{
init();
int u, v;
while(scanf("%d", &u) && u)
{
while(getchar()!='\n')
{
scanf("%d", &v);
addedge(u, v);
addedge(v, u);
}
} Tarjan(, );
int ans = ;
for(int i = ; i<=n; i++)
if(cut[i]) ans++; printf("%d\n", ans);
}
}
UVA315 Network —— 割点的更多相关文章
- uva-315.network(连通图的割点)
本题大意:求一个无向图额割点的个数. 本题思路:建图之后打一遍模板. /**************************************************************** ...
- [UVA315]Network(tarjan, 求割点)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA315 Network 连通图割点
题目大意:有向图求割点 题目思路: 一个点u为割点时当且仅当满足两个两个条件之一: 1.该点为根节点且至少有两个子节点 2.u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的 ...
- poj 1144 Network(割点)
题目链接: http://poj.org/problem?id=1144 思路分析:该问题要求求出无向联通图中的割点数目,使用Tarjan算法即可求出无向联通图中的所有的割点,算法复杂度为O(|V| ...
- poj 1144 Network(割点 入门)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10907 Accepted: 5042 Descript ...
- UVA315 Network
割点的概念:对于无向图,删除这个点与其相连的边,整个图的连通分量个数增加. 对于无向图的tarjan算法,必须要设前驱~ 求割点的模板~ #include<cstdio> #include ...
- 连通图(Tarjan算法) 专题总结
一.题目类型: 1.有向图的强连通分量: POJ1236 Network of Schools HDU1269 迷宫城堡 2.割点 & 割边: UESTC - 900 方老师炸弹 UVA315 ...
- UVA315:Network(求割点)
Network 题目链接:https://vjudge.net/problem/UVA-315 Description: A Telephone Line Company (TLC) is estab ...
- Network -UVa315(连通图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=sh ...
随机推荐
- Java面向对象重要关键字
面向对象过程接触的重要关键字:extends super this final static extends 关键字用作继承功能,可以申明一个类是从另外一个类继承而来的,一般形式如下 ...
- css中background-image背景图片路径设置
web项目中经常会用到background-image:url(),很多小伙伴不知道该怎么写需要的图片路径. 在此之前先要知道几个重要的东东: / 项目根目录 这个不用多说,就是程序 ...
- JS 回车跳转
window.onload = function () { SeteasyuiTheme(); jQuery(':input:enabled').addClass('enterIndex'); var ...
- [luoguP1947] 笨笨当粉刷匠_NOI导刊2011提高(10)(DP)
传送门 f[i][j][k]表示前i行,最后一行前j个,选k次最优解 ntr[i][j][2]表示当前行区间i~j涂0或1所能刷的正确格子 #include <cstdio> #defin ...
- Toad Oracle 本地/远程数据库导入/导出 数据库备份
1. Toad进入数据库后,选择 Database ==> Export ===> Export Utility Wizard ,选择export user(按用户导出),选择Toa ...
- 【BZOJ1717&POJ3261】Milk Patterns(后缀数组,二分)
题意:求字符串的可重叠的k次最长重复子串 n<=20000 a[i]<=1000000 思路:后缀数组+二分答案x,根据height分组,每组之间的height>=x 因为可以重叠, ...
- msp430入门编程25
msp430中C语言开发环境搭建 msp430入门学习 msp430入门编程
- Sigar 编译笔记
https://blog.csdn.net/zw3413/article/details/79482438
- 学习日常笔记<day12>jsp基础
1.Jsp基础 1.1Jsp引入 Servlet的作用:用java语言开发动态资源的技术 Jsp的作用:用java语言(+html语言)开发动态资源的技术 jsp就是servlet 1.2Jsp的特点 ...
- final finally finalize 区别及用法
final 1,final修饰的class,代表不可以继承扩展. 2.final的方法也是不可以重写的. 3.final修饰的变量是不可以修改的.这里所谓的不可修改对于基本类型来来,的确是不可以修改. ...