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 ...
随机推荐
- HDU1280前m大的数creat at 9:51,3.13,2016
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- html template & import link bug
html template & import link bug html templates is OK https://caniuse.com/#search=html%20template ...
- POJ1061青蛙的约会
Description 两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事 ...
- 【字符串+BFS】Problem 7. James Bond
https://www.bnuoj.com/v3/external/gym/101241.pdf [题意] 给定n个字符串,大小写敏感 定义一个操作:选择任意m个串首尾相连组成一个新串 问是否存在一个 ...
- Flex4分模块下样式动态加载步骤及相关问题的解决
1. 给应用程序编写CSS文件 (1)在项目下创建CSS文件(任意路径,可以多个).本例在src下创建了5个样式文件 (2)Flex支持的CSS文件定义如下: a) type selector(类 ...
- C/C++ (一)
c语言中的逻辑运算符都是短路运算,一旦能够确定整个表达式的值就不再计算,配合c的定义的灵活性,可以写出很多漂亮的程序. 例如 如果要在一个长为n的数列s中找到第k个没被标记过的数 for(i=1,j= ...
- hdu6196 happpy happy happy (meet in middle + 剪枝)
题意 从1到n共计n(<=90)个物品,每个物品有一个价值a[i],儿子和爸爸轮流做游戏,儿子先手.儿子每次选价值最大的{最左边,最右边}的物品,如果价值一样大, 则选取最左边的物品. 爸爸每次 ...
- pcre7.0在vc6.0编译
(0)从http://gnuwin32.sourceforge.net/packages/pcre.htm (pcre windows)下下载最新的windows平台源代码pcre-7.0-src. ...
- linux下启动mysql服务(类似于windows下net start mysql)
1.linux系统启动方式:service mysql start.其类似于windows下net start mysql
- Visual Studio VS如何拷贝一个项目的窗体文件到另一个项目
1 比如下我有一个项目,我要把这个Config整个窗体和代码拷贝到另一个项目 2 在新项目中添加现有项,然后把这个窗体相关的三个文件都添加到新的项目中 3 然后在新窗体中就什么都有了 ...