UVA315:Network(求割点)
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(求割点)的更多相关文章
- uva315(求割点数目)
传送门:Network 题意:给出一张无向图,求割点的个数. 分析:模板裸题,直接上模板. #include <cstdio> #include <cstring> #incl ...
- UVA315 Network 连通图割点
题目大意:有向图求割点 题目思路: 一个点u为割点时当且仅当满足两个两个条件之一: 1.该点为根节点且至少有两个子节点 2.u不为树根,且满足存在(u,v)为树枝边(或称 父子边,即u为v在搜索树中的 ...
- Network -UVa315(连通图求割点)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=sh ...
- UVA-315 无向图求割点个数
题意抽象: 给定一个无向图,输出割点个数. 割点定义:删除该点后,原图变为多个连通块. 考虑一下怎么利用tarjan判定割点: 对于点u和他相连的当时还未搜到的点v,dfs后如果DFN[u]<= ...
- [UVA315]Network(tarjan, 求割点)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- (连通图 模板题 无向图求割点)Network --UVA--315(POJ--1144)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA315 Network —— 割点
题目链接:https://vjudge.net/problem/UVA-315 A Telephone Line Company (TLC) is establishing a new telepho ...
- uva-315.network(连通图的割点)
本题大意:求一个无向图额割点的个数. 本题思路:建图之后打一遍模板. /**************************************************************** ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
随机推荐
- Python 默认参数值
Python 默认参数值,对于一些函数来说,你可能为希望使一些参数可选并使用默认的值,以避免用户不想为他们提供值的情况.默认参数值可以有效帮助解决这一情况.你可以通过在函数定义时附加一个赋值运算符(= ...
- 关于java中“使用了未经检查或不安全的操作、有关详细信息,请使用 ——Xlint:unchecked重新编译”
今天看<算法 第4版>排序章节时,发现了一个了一个小问题.先贴一下代码: public class Selection{ public static void main(String[]a ...
- ArrayList与LinkedList的普通for循环遍历
对于大部分Java程序员朋友们来说,可能平时使用得最多的List就是ArrayList,对于ArrayList的遍历,一般用如下写法: public static void main(String[] ...
- 完全背包问题 :背包dp
题目描述: 有 N种物品和一个容量是 V 的背包,每种物品都有无限件可用.第 i 种物品的体积是 vi,价值是 wi. 求解将哪些物品装入背包,可使这些物品的总体积不超过背包容量,且总价值最大.输出最 ...
- springMVC怎么改变form的提交方式为put或者delete
想着练习一下创建restful风格的网站呢,结果发现在jsp页面上并不能灵活使用put和delete提交方式.下面我的解决办法 一. form 只支持post和get两种提交方式,只支持get提交方式 ...
- 六:YARN Node Labels
参考:http://dongxicheng.org/mapreduce-nextgen/hadoop-yarn-label-based-scheduling/ 为不同的DATANODE打标签,通过标签 ...
- PHPCMS v9表单向导中怎么加入验证码
表单想到比较简单,所以没有加入验证码的功能.网上的类似教程又大多数不准确.所以亲自测试了一下,发现下面的方法是可用的.希望对有需求的朋友们有所帮助. 1.首先是调用表单的页面加入验证码.表单js调用模 ...
- 软件工程 speedsnail 第二次冲刺9
20150526 完成任务:划线的优化,速度和谐: 遇到问题: 问题1 速度仍然不满意 解决1 未解决 明日任务: 蜗牛碰到线后速度方向的调整:(做优化)
- 算法与数据结构实验题 4.2 小 F 打怪
★实验任务 小 F 很爱打怪,今天因为系统 bug,他提前得知了 n 只怪的出现顺序以及击 倒每只怪得到的成就值 ai.设第一只怪出现的时间为第 1 秒,这个游戏每过 1 秒 钟出现一只新怪且没被击倒 ...
- [基于NetCore的简单博客系统]-登录
0-项目背景 一个基于.NET CORE RAZOR PAGES的简单博客系统 技术栈全部采用微软官方实现方式,目的是熟悉新技术 项目地址:https://github.com/ganqiyin/BL ...