SPF
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8155   Accepted: 3730

Description

Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on the left would prevent some of the still available nodes from communicating with each other. Nodes 1 and 2 could still communicate with each other as could nodes 4 and 5, but communication between any other pairs of nodes would no longer be possible.

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

The
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

For each network in the input, you will output its number in the file, followed by a list of any SPF nodes that exist.

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(寻找关节点)的更多相关文章

  1. poj 1523 SPF(双连通分量割点模板)

    题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...

  2. zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)

    poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...

  3. POJ 1523 SPF 割点与桥的推断算法-Tarjan

    题目链接: POJ1523 题意: 问一个连通的网络中有多少个关节点,这些关节点分别能把网络分成几部分 题解: Tarjan 算法模板题 顺序遍历整个图,能够得到一棵生成树: 树边:可理解为在DFS过 ...

  4. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

  5. POJ 1523 SPF(求割点)

    题目链接 题意 : 找出图中所有的割点,然后输出删掉他们之后还剩多少个连通分量. 思路 : v与u邻接,要么v是u的孩子,要么u是v的祖先,(u,v)构成一条回边. //poj1523 #includ ...

  6. POJ 1523 SPF (割点,连通分量)

    题意:给出一个网络(不一定连通),求所有的割点,以及割点可以切分出多少个连通分量. 思路:很多种情况. (1)如果给的图已经不是连通图,直接“  No SPF nodes”. (2)求所有割点应该不难 ...

  7. zoj 1119 /poj 1523 SPF

    题目描述:考虑图8.9中的两个网络,假定网络中的数据只在有线路直接连接的2个结点之间以点对点的方式传输.一个结点出现故障,比如图(a)所示的网络中结点3出现故障,将会阻止其他某些结点之间的通信.结点1 ...

  8. POJ - 1523 SPF

    题目要求割顶集,并且还要求出去掉割顶之后剩下的图连通数目. tarjan算法求出割顶后直接枚举就可以了吧. 一开始想到利用iscut[u]的次数也就是点u被判定为割顶的次数求连通分量数,还有利用与结点 ...

  9. poj 1523 SPF【点双连通求去掉割点后bcc个数】

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7246   Accepted: 3302 Description C ...

随机推荐

  1. windows下安装openssh服务并实现远程登录

    需要准备的工具: winscp 点击下载        openssh 点击下载  步骤: 在远程计算机安装 1.首先安装openssh,双击并安装 2.指定用户的home directory为C:\ ...

  2. 结构化视角看django

    分析一个软件的整体框架,我认为应该从静态和动态两方面入手.静态方面,看它有哪些用例,即有哪些功能模块:动态方面,看主流程如何连接上这些模块 静态方面:分View.Model.Template.Sess ...

  3. 深入理解mybatis参数

    这个的话我是看的别人的文章,感觉很好: http://blog.csdn.net/isea533/article/details/44002219

  4. 【python】import 模块、包、第三方模块

    xx.py文件,称为模块(module),把不同模块归整到一起的文件夹,叫做包(package) 不同包下的模块可以重名,但是都不能和系统内建模块重名 包里面一定要有个__init__.py文件,否则 ...

  5. 理解NSAttributedString

    An NSAttributedString object manages character strings and associated sets of attributes (for exampl ...

  6. Ubuntu 14.10 下网络流量实时监控ifstat iftop命令详解

    ifstat 介绍 ifstat工具是个网络接口监测工具,比较简单看网络流量 实例 默认使用 #ifstat eth0 eth1 KB/s in KB/s out KB/s in KB/s out 0 ...

  7. 2016-1-5第一个完整APP 私人通讯录的实现 1:登录界面及跳转的简单实现2

    ---恢复内容开始--- 实际效果如上 一:Segue的学习 1.什么是Segue: Storyboard上每一根用来界面跳转的线,都是一个UIStoryboardSegue对象(简称Segue)   ...

  8. C++11 std::copy

    这个函数并不是简单的 while(first != last) { *result = *first; result++; first++; } 事实上这种写法是最具普适性的,值要求inputIter ...

  9. 利用strut2标签自动生成form前端验证代码

    利用strut2标签自动生成form前端验证代码,使用到的技术有1.struts2标签,如<s:form> <s:textfieled>2.struts2读取*Validati ...

  10. GSM BTS Hacking: 利用BladeRF和开源BTS 5搭建基站

    引文 如果你已经购买了Nuand(官方)BladeRF x40,那么就可以在上面运行OpenBTS并可以输入一些指令来完成一些任务.一般来说HackRF,是一款覆盖频率最宽的SDR板卡.它几乎所有的信 ...