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. 完整的正则表达式知识汇总(Python知识不断更新)

    ## 大纲: ## 一.正则概述 1.正则是什么 正则就是一套规则,或者语法 2.正则的作用 让我们判断是否符合我们的的规则,或者根据规则找到符合规则的数据 3.使用场景 可以用正则判断我们输入的邮箱 ...

  2. Vue 编程之路(二)——跳转页面传值

    最近公司的一个项目中使用 Vue 2.0 + element UI 实现一个后台管理系统的前端部分,属于商城类型.其中我负责的部分有一项需要跳转页面,由于跳转前的页面是多个组件构成的,所以在跳转页面的 ...

  3. sparksql读写hbase

    //写入hbase(hfile方式) org.apache.hadoop.hbase.client.Connection conn = null; try { SparkLog.debug(" ...

  4. [leetcode-744-Find Smallest Letter Greater Than Target]

    Given a list of sorted characters letters containing only lowercase letters, and given a target lett ...

  5. BZOJ 4361 isn 容斥+dp+树状数组

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4361 题意概述: 给出一个长度为N的序列A(A1,A2...AN).如果序列A不是非降的 ...

  6. POJ 3415 Common Substrings(后缀数组)

    Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. Given t ...

  7. Python中的namespace package

    在Python 3.3之前,一个目录想被当成package被导入,必须包含__init__.py文件:而在Python 3.3及以后的版本中,__init__.py文件可以不需要,直接使用import ...

  8. c# throw抛出上一个异常

    catch(exception e) { throw; } 不仅抛出这次的异常,也抛出之前的异常. 用法示例:函数A调用函数B,A用到此throw时,B中发生的异常也会继承过来. catch(exce ...

  9. 【Android 应用开发】Ubuntu 下 Android Studio 开发工具使用详解

    . 基本上可以导入项目开始使用了 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21035637 ...

  10. union查询

     select id, uid, money, FROM_UNIXTIME(created) as created, type FROM  (  #type=1是  cjw_finance_bonus ...