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小项目,Github上的人气很高的

    1.深度学习框架 Pytorch https://github.com/pytorch/pytorch PyTorch 是一个 Torch7 团队开源的 Python 优先的深度学习框架,提供两个高级 ...

  2. day21 TFRecord格式转换MNIST并显示

    首先简要介绍了下TFRecord格式以及内部实现protobuf协议,然后基于TFRecord格式,对MNIST数据集转换成TFRecord格式,写入本地磁盘文件,再从磁盘文件读取,通过pyplot模 ...

  3. 使用DataTables导出html表格

    去年与同事一起做一个小任务,需要把HTML表格中的数据导出到Excel.用原生js想要实现,只有IE浏览器提供导出到微软的Excel的接口,这就要求你电脑上必须安装IE浏览器.Excel,而且必须修改 ...

  4. 软件工程课堂作业(十一)——NABC分析

    一.团队开发项目:基于Android的重力感应的解锁APP 二.项目特点:区别于一般解锁软件用开机按钮开锁解锁,我们的重力解锁软件根据动作实现解锁,减少了开机按钮的使用频率,提高寿命. 三.NABC分 ...

  5. Khan Academy

    Khan Academy是一个免费的学院. 致力于教育改革. 百度百科:ohn Resig 百度百科有记者采访,采访内容比较有意思.

  6. java线程安全— synchronized和volatile

    java线程安全— synchronized和volatile package threadsafe; public class TranditionalThreadSynchronized { pu ...

  7. LintCode-140.快速幂

    快速幂 计算an % b,其中a,b和n都是32位的整数. 样例 例如 231 % 3 = 2 例如 1001000 % 1000 = 0 挑战 O(logn) 标签 分治法 code class S ...

  8. C++多态实现与继承

    面向对象的三个基本特征 面向对象的三个基本特征是:封装.继承.多态.其中, 封装可以隐藏实现细节,使得代码模块化: 继承可以扩展已存在的代码模块(类),它们的目的都是为了——代码重用: 而多态则是为了 ...

  9. php中的<?= ?>替换<?php echo ?>

    首先修改PHP.ini文件.如下: 1. 将short_open_tag = Off 改成On 开启以后可以使用PHP的短标签:<? ?> <?= $test ?>来代替 &l ...

  10. mysql+navicat安装小结

    1,mysql到官方下载,navicat下载破解版 2,修改my.ini, 注意,需要手动创建data文件夹, 其中C:\MySql\mysql-5.7.17-winx64是解压mysql的目录 [m ...