Network

题目链接:https://vjudge.net/problem/UVA-315

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

题意:

给出一个无向图,问割点的个数。

题解:

就是求割点的模板题,利用时间戳来求,注意最后判断一下根的情况。

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int N = ;
int n;
int head[N];
struct Edge{
int u,v,next;
}e[N*N<<];
int T,tot;
int dfn[N],low[N],cut[N];
void adde(int u,int v){
e[tot].v=v;e[tot].next=head[u];head[u]=tot++;
}
void init(){
memset(head,-,sizeof(head));tot=;
memset(cut,,sizeof(cut));T=;
memset(dfn,,sizeof(dfn));
}
void Tarjan(int u,int pre){
dfn[u]=low[u]=++T;
int son=;
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(v==pre) continue ; if(!dfn[v]){
son++;
Tarjan(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]&&u!=pre)cut[u]=;
}else{
low[u]=min(low[u],dfn[v]);
}
}
if(u==pre && son>) cut[u]=;
}
int main(){
while(scanf("%d",&n)&&n){
int u;char ch;
init();
while(scanf("%d",&u)&&u){
int v;
while(){
scanf("%d%c",&v,&ch);
adde(u,v);adde(v,u);
if(ch=='\n') break ;
}
}
for(int i=;i<=n;i++){
if(!dfn[i]) Tarjan(i,i);
}
int ans = ;
for(int i=;i<=n;i++){
if(cut[i]) ans++;
}
cout<<ans<<endl;
}
return ;
}

UVA315:Network(求割点)的更多相关文章

  1. uva315(求割点数目)

    传送门:Network 题意:给出一张无向图,求割点的个数. 分析:模板裸题,直接上模板. #include <cstdio> #include <cstring> #incl ...

  2. UVA315 Network 连通图割点

    题目大意:有向图求割点 题目思路: 一个点u为割点时当且仅当满足两个两个条件之一: 1.该点为根节点且至少有两个子节点 2.u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的 ...

  3. Network -UVa315(连通图求割点)

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

  4. UVA-315 无向图求割点个数

    题意抽象: 给定一个无向图,输出割点个数. 割点定义:删除该点后,原图变为多个连通块. 考虑一下怎么利用tarjan判定割点: 对于点u和他相连的当时还未搜到的点v,dfs后如果DFN[u]<= ...

  5. [UVA315]Network(tarjan, 求割点)

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

  6. (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)

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

  7. UVA315 Network —— 割点

    题目链接:https://vjudge.net/problem/UVA-315 A Telephone Line Company (TLC) is establishing a new telepho ...

  8. uva-315.network(连通图的割点)

    本题大意:求一个无向图额割点的个数. 本题思路:建图之后打一遍模板. /**************************************************************** ...

  9. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

随机推荐

  1. 【system.folder】使用说明

    对象:system.folder 说明:提供一系列针对文件夹的操作 目录: 方法 返回 说明 system.folder.exists(folderPath) [True | False] 检测指定文 ...

  2. leetcode-三数之和(java)

     三数之和     给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可 ...

  3. Leetcode - 557. Reverse Words in a String III (C++) stringstream

    1. 题目:https://leetcode.com/problems/reverse-words-in-a-string-iii/discuss/ 反转字符串中的所有单词. 2. 思路: 这题主要是 ...

  4. 2018java开发一些面经

    算法系列:https://www.cnblogs.com/yanmk/p/9232908.html 2018Java开发面经(持续更新) 不要给自己挖坑!!!不要给自己挖坑!!!不要给自己挖坑!!!如 ...

  5. windows编程入门最重要的

    要入门 Windows 编程,最重要的不是阅读什么教材,使用什么工具,而是先必须把以下几个对于初学者来说非常容易困惑的重要概念搞清楚: 1. 文字的编码和字符集.这部分需要掌握 ANSI 模式和 Un ...

  6. M2功能规格说明书

    1.目的: 这篇随笔是简述我们团队所做的工程所能实现的功能及方便用户的使用. 2.假定和约束: 我们先限定为本地连接数据库进行各种操作的实现.用户电脑中需要有FLASH工具及快播插件.其他只需要了解基 ...

  7. from module import 和 import 的区别

    最近在用codecademy学python,遇到一些题目错误,小小记录一下 如from math import sqrt是把sqrt作为本文件的方法导入进来了,使用的时候只需要直接调用sqrt. 而如 ...

  8. Qt自定义标题栏

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt自定义标题栏     本文地址:http://techieliang.com/2017/1 ...

  9. 【Docker 命令】- ps命令

    docker ps : 列出容器 语法 docker ps [OPTIONS] OPTIONS说明: -a:显示所有的容器,包括未运行的. -f:根据条件过滤显示的内容. --format :指定返回 ...

  10. Jenkins系列-Jenkins升级、迁移和备份

    升级Jenkins Jenkins的开发迭代非常快,每周发布一个开发版本,长期支持版每半年更新一次(ps:大版本更新).如此频繁的更新,怎么升级呢? war:下载新版的war文件,替换旧版本war文件 ...