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 ...
随机推荐
- 大学生成绩管理系统(C语言)
功能:成绩管理系统包含了学生的全部信息,每个学生是一个记录,包括学号,姓名,性别,班级,各科成绩(语数外). 系统功能: 1.信息录入——录入学生信息: 2.信息输出——显示所有信息: 3.信息查询— ...
- Section 1.4 The Clocks
0 0 虽然不知不觉做到了Section 1.4了,但是都没有把做题的想法和代码发到这里… 本来今天想从Section 1.2补起来然后发现之前做的题都忘了…(Name That Number那道题是 ...
- bitmapData
一些常用接口: clone(): 得到位图数据的拷贝: 用途:深复制位图 draw(source :IBitmapDrawable...): source 要绘制到 BitmapData 对象的显示对 ...
- S5PV210之添加缺少的-内核提供的'.h'文件 linux3.0.8驱动
怎样解决编译时出现内核提供的函数或变量没有定义,使用source insight搜索功能找到声明的头文件,然后包含该头件就行了: 比如: error: implicit declaration of ...
- java基础-002
1.Java虚拟机和“平台无关语言” Java虚拟机是可以执行字节码的虚拟机进程.Java源文件被编译成被Java虚拟机执行的字节码文件. Java被设计成允许应用程序运行在任意的平台,而不需要程序员 ...
- mybatis 参数问题
load方法,往sql语句中传一个参数的那种,似乎parameterType并不是那么重要,不写其实都可以,而且sql语句中的比如username=#{A} 这里面的A可以随便写,只要传过来的是个St ...
- Java运算符及顺序、选择结构
:运算符(掌握) ()算术运算符 A:+,-,*,/,%,++,-- B:+的用法 a:加法 b:正号 c:字符串连接符 C:/和%的区别 数据做除法操作的时候,/取得是商,%取得是余数 D:++和- ...
- 功率与dbm的对照表
功率与dbm的对照表 分类: 嵌入式 功率与dbm的对照表 对于无线工程师来说更常用分贝dBm这个单位,dBm单位表示相对于1毫瓦的分贝数,dBm和W之间的关系是:dBm=10*lg(mW)1w的功 ...
- H5实现俄罗斯方块(二)
对应的js 1.封装操作dom的js: (function (document) { //游戏的实例 var gameInst; /**封装一个返回原型的DOM对象 */ function DomOb ...
- C++之创建对象时的new与不new
C++在创建对象的时候可以采用两种方式:(例如类名为Test) Test test 或者 Test* pTest = new Test(). 这两种方法都可以实例化一个对象,但是这两种方法有很大的区 ...