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 ...
随机推荐
- luogu3960 列队
参考这篇 #include <iostream> #include <cstdio> #include <vector> using namespace std; ...
- 【BZOJ1403】Divisibility Testing(数论)
题意: 思路: #include<cstdio> #include<cstdlib> #include<algorithm> #include<map> ...
- 远程连接mongodb时,27017端口连接不上的解决办法
一.背景描述: 我在linux RED7上安装了mongodb,并没有修改mongodb的配置文件.然后通过另外一台电脑用pymongo连接mongodb时,报错:timeout. ping IP ...
- 钱币兑换问题---hdu1284(完全背包)
Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法.请你编程序计算出共有多少种兑法. Input 每行只有一个正整数N,N小于32768. ...
- Java面试题总结(一)---Java基础
Java面试题总结(一)---Java基础 1.面向对象的特征有哪些? 答:面向对象的特征主要有以下几个: 1)抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方 ...
- Hive安装中遇到过的坑
实现说明每一个用户的环境都有细微的不一致,所以这里只是个人经过这些坑的处理,但是不意味着所有处理都是这样的操作,仅作为参考. 第一个坑 数据库安装,数据库最好装在Linux上,一直出了很多错,这里有一 ...
- Ubuntu 16.04安装Guake Terminal终端(使用一键唤醒功能)
安装: sudo apt-get install guake-indicator sudo apt-get install guake 使用: 先启动guake-indicator,再启动guake. ...
- how to read openstack code: loading process
之前我们了解了neutron的结构,plugin 和 extension等信息.这一章我们看一下neutron如何加载这些plugin和extension.也就是neutron的启动过程.本文涉及的代 ...
- Jmeter的几个关键配置文件
1.配置文件位于bin目录下: 2.配置文件可能存在优先级关系,好像user.properties会覆盖jmeter.properties,一般修改配置都是修改或者添加user.properties, ...
- 【APUE】进程间通信之消息队列
三种IPC的共同特征 1.标识符和键 每个内核中的IPC结构都用一个非负整数的标识符加以引用.当一个IPC结构被创建,以后又被删除时,与这种结构相关的标识符连续加1,直至达到一个整型数的最大值,然后又 ...