POJ 1523 SPF(寻找关节点)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8155 | Accepted: 3730 |
Description
Node 3 is therefore a Single Point of Failure (SPF) for this
network. Strictly, an SPF will be defined as any node that, if
unavailable, would prevent at least one pair of available nodes from
being able to communicate on what was previously a fully connected
network. Note that the network on the right has no such node; there is
no SPF in the network. At least two machines must fail before there are
any pairs of available nodes which cannot communicate.
Input
input will contain the description of several networks. A network
description will consist of pairs of integers, one pair per line, that
identify connected nodes. Ordering of the pairs is irrelevant; 1 2 and 2
1 specify the same connection. All node numbers will range from 1 to
1000. A line containing a single zero ends the list of connected nodes.
An empty network description flags the end of the input. Blank lines in
the input file should be ignored.
Output
The first network in the file should be identified as "Network #1",
the second as "Network #2", etc. For each SPF node, output a line,
formatted as shown in the examples below, that identifies the node and
the number of fully connected subnets that remain when that node fails.
If the network has no SPF nodes, simply output the text "No SPF nodes"
instead of a list of SPF nodes.
Sample Input
1 2
5 4
3 1
3 2
3 4
3 5
0 1 2
2 3
3 4
4 5
5 1
0 1 2
2 3
3 4
4 6
6 3
2 5
5 1
0 0
Sample Output
Network #1
SPF node 3 leaves 2 subnets Network #2
No SPF nodes Network #3
SPF node 2 leaves 2 subnets
SPF node 3 leaves 2 subnets
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#define inf 0x7fffffff
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ; int edg[N][N],vis[N];
int nodes,tmpdfn,son;
int dfn[N],low[N],subnets[N];
void init()
{
low[]=dfn[]=;
tmpdfn=;son=;
met(vis,);met(subnets,);
vis[]=;
}
void Tarjan(int u)
{
for(int v=;v<=nodes;v++){
if(edg[u][v]){
if(!vis[v]){
vis[v]=;
dfn[v]=low[v]=++tmpdfn;
Tarjan(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
if(u!=)subnets[u]++;
else son++;
}
}
else low[u]=min(low[u],dfn[v]);
}
}
}
int main()
{
int u,v,num=;
while(~scanf("%d",&u)&&u){
met(edg,);nodes=;
scanf("%d",&v);
nodes=max(max(u,v),nodes);
edg[u][v]=edg[v][u]=;
while(){
scanf("%d",&u);
if(!u)break;
scanf("%d",&v);
nodes=max(max(u,v),nodes);
edg[u][v]=edg[v][u]=;
}
if(num>)printf("\n");
printf("Network #%d\n",num);num++;
init();
Tarjan();
if(son>)subnets[]=son-;
bool find=false;
for(int i=;i<=nodes;i++){
if(subnets[i]){
find=true;printf(" SPF node %d leaves %d subnets\n",i,subnets[i]+);
}
}
if(!find)printf(" No SPF nodes\n");
}
return ;
}
POJ 1523 SPF(寻找关节点)的更多相关文章
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)
poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...
- POJ 1523 SPF 割点与桥的推断算法-Tarjan
题目链接: POJ1523 题意: 问一个连通的网络中有多少个关节点,这些关节点分别能把网络分成几部分 题解: Tarjan 算法模板题 顺序遍历整个图,能够得到一棵生成树: 树边:可理解为在DFS过 ...
- POJ 1523 SPF tarjan求割点
SPF Time Limit: 1000MS Memory Limit ...
- POJ 1523 SPF(求割点)
题目链接 题意 : 找出图中所有的割点,然后输出删掉他们之后还剩多少个连通分量. 思路 : v与u邻接,要么v是u的孩子,要么u是v的祖先,(u,v)构成一条回边. //poj1523 #includ ...
- POJ 1523 SPF (割点,连通分量)
题意:给出一个网络(不一定连通),求所有的割点,以及割点可以切分出多少个连通分量. 思路:很多种情况. (1)如果给的图已经不是连通图,直接“ No SPF nodes”. (2)求所有割点应该不难 ...
- zoj 1119 /poj 1523 SPF
题目描述:考虑图8.9中的两个网络,假定网络中的数据只在有线路直接连接的2个结点之间以点对点的方式传输.一个结点出现故障,比如图(a)所示的网络中结点3出现故障,将会阻止其他某些结点之间的通信.结点1 ...
- POJ - 1523 SPF
题目要求割顶集,并且还要求出去掉割顶之后剩下的图连通数目. tarjan算法求出割顶后直接枚举就可以了吧. 一开始想到利用iscut[u]的次数也就是点u被判定为割顶的次数求连通分量数,还有利用与结点 ...
- poj 1523 SPF【点双连通求去掉割点后bcc个数】
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7246 Accepted: 3302 Description C ...
随机推荐
- High Performance Django
构建高性能Django站点 性能 可用 伸缩 扩展 安全 build 1.审慎引入第三方库(是否活跃.是否带入query.是否容易缓存) 2.db:减少query次数 减少耗时query 减小返回 ...
- NTP服务器的配置
安装cloudera Manager的时候,必须要求集群的主机之间时间同步,搭建一个NTP服务器的思路是,首先通过一台主机master与外网进行时间同步,然后其他的slaver主机与主机master进 ...
- KeySweeper 微软无线键盘嗅探装置
Author:Samy Kamkar From: http://samy.pl/keysweeper/ 中文字幕由Galaxy无名提供 PS:视频传到youku之后发现50秒左右的字幕被干掉了,不知道 ...
- Interview----2 sum
题目:输入一个已经按升序排序过的数组和一个数字, 在数组中查找两个数,使得它们的和正好是输入的那个数字. 要求时间复杂度是 O(n).如果有多对数字的和等于输入的数字,输出任意一对即可. 例如输入数组 ...
- JQuery源码分析(三)
jQuery中ready与load事件 jQuery有3种针对文档加载的方法 $(document).ready(function() { // ...代码... }) //document read ...
- 【Android UI】 Shape详解
在Android开发过程中,经常需要改变控件的默认样式, 那么通常会使用多个图片来解决.不过这种方式可能需要多个图片,比如一个按钮,需要点击时的式样图片,默认的式样图片. 这样就容易使apk变大. 那 ...
- Inno Setup脚本语法大全
Inno Setup脚本语法大全 ResourceShare Bruce 11个月前 (10-28) 6136浏览 0评论 Inno Setup 是什么?Inno Setup 是一个免费的 Win ...
- LeetCode First Bad Version (二分查找)
题意: 有一个bool序列表示对应下标的版本是否出问题(下标从1开始),如果一个版本出了问题,那么其后面全部版本必定出问题.现在给出判断任意版本是否出问题的API,请找到第一个出问题的版本. 思路: ...
- 传智springMVC笔记
springmvc 第一天 springmvc的基础知识 课程安排: 第一天:springmvc的基础知识 什么是springmvc? springmvc框架原理(掌握) 前端控制器.处理器映射器.处 ...
- C语言Makefile文件使用
C语言中代码Makefile文件的写法 单文件,例: #定义变量 CFLAGS=gcc #具体命令都需要一个入口,all: 这个就相当于入口,默认情况,执行第一次入口, #后面执行其他入口进行依赖,如 ...