Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8254   Accepted: 3772

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

Source

点双连通分量模板题

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
struct edge{
int v,nxt;
}e[mxn<<];
int hd[mxn],mct=;
void add_edge(int u,int v){
e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;
return;
}
int n;
int low[mxn],dfn[mxn],dtime=;
int num[mxn];
int st[mxn],top=;
bool cut[mxn];
void DFS(int u,int fa){
low[u]=dfn[u]=++dtime;
st[++top]=u;
int i,j;
for(i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(v==fa)continue;
if(!dfn[v]){
DFS(v,u);
if(low[v]>=dfn[u]){
cut[u]=;
int s=;
do{
s=st[top--];
++num[s];
}while(u!=s);
top++;
}
// num[u]++;
low[u]=min(low[u],low[v]);
}
else low[u]=min(dfn[v],low[u]);
}
return;
}
bool have[mxn];
int main(){
int cas=;
while(){
memset(hd,,sizeof hd);
memset(cut,,sizeof cut);
memset(low,,sizeof low);
memset(dfn,,sizeof dfn);
memset(have,,sizeof have);
memset(num,,sizeof num);
mct=dtime=top=;
int i,j,u,v;
bool flag=;
while(scanf("%d",&u) && u){
scanf("%d",&v);
have[u]=have[v]=;
add_edge(u,v);
add_edge(v,u);
flag=;
}
if(!flag)break;
for(i=;i<=;i++)
if(have[i] && !dfn[i])DFS(i,);
printf("Network #%d\n",++cas);
flag=;
for(i=;i<=;i++){
if(num[i]>=){
flag=;
printf(" SPF node %d leaves %d subnets\n",i,num[i]);
}
}
if(!flag)printf(" No SPF nodes\n");
printf("\n");
}
return ;
}

POJ1523 SPF的更多相关文章

  1. POJ1523 SPF[无向图割点]

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8139   Accepted: 3723 Description C ...

  2. POJ1523 SPF 单点故障

    POJ1523 题意很简单,求删除割点后原先割点所在的无向连通图被分成了几个连通部分(原题说prevent at least one pair of available nodes from bein ...

  3. POJ1523 SPF(割点模板)

    题目求一个无向图的所有割点,并输出删除这些割点后形成几个连通分量.用Tarjan算法: 一遍DFS,构造出一颗深度优先生成树,在原无向图中边分成了两种:树边(生成树上的边)和反祖边(非生成树上的边). ...

  4. POJ1523:SPF(无向连通图求割点)

    题目:http://poj.org/problem?id=1523 题目解析: 注意题目输入输入,防止PE,题目就是求割点,并问割点将这个连通图分成了几个子图,算是模版题吧. #include < ...

  5. poj图论解题报告索引

    最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...

  6. Tarjan求割点和桥

    by szTom 前置知识 邻接表存储及遍历图 tarjan求强连通分量 割点 割点的定义 在一个无向图中,如果有一个顶点集合,删除这个顶点集合以及这个集合中所有顶点相关联的边以后,图的连通分量增多, ...

  7. POJ1523:SPF——题解

    http://poj.org/problem?id=1523 这题明显就是求割点然后求割完之后的强连通分量的个数. 割点都会求,怎么求割完的分量个数呢? 我们可以通过万能的并查集啊!(具体做法看代码吧 ...

  8. POJ 1523 SPF(求割点)

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

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

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

随机推荐

  1. java 16 -7 泛型方法和泛型接口(泛型类相似)

    写一个ObjectTool类 泛型方法:把泛型定义在方法上 格式 public <泛型类型> 返回类型 方法名(泛型类型) 这样的好处是: 这个泛型方法可以接收任意类型的数据 public ...

  2. angularjs: ng-select和ng-options

    angular.js有一个很强大的指令: ng-select 它可以帮助你通过数据模型来创建select元素.它很好的支持了select标签的语法,但是却有点坑. 假设有如下一段json数据: { & ...

  3. linux下的zip命令

    1.把/home目录下面的mydata目录压缩为mydata.zipzip -r mydata.zip mydata #压缩mydata目录2.把/home目录下面的mydata.zip解压到myda ...

  4. Linux 发送信号

    使用kill命令 --在命令行执行kill命令.向指定进程发送信号. 使用kill函数 int kill(pid_t pid,int sig); --参数pid指定一个要杀死的进程,而sig是要发送的 ...

  5. matlab矩阵合并及相关运算

    1.matlab允许向量(和矩阵)合并,且matlab提供了两种合并方式,[a,b]和[a;b],两者的结果是不一样的. a=rand(2,3): b=rand(2,3): c=[a;b]: d=[a ...

  6. Activiti系列:如何把Activiti工程转换为maven工程以解决依赖项找不到的问题

    在eclipse中安装了Activiti插件之后,就可以新建Activiti工程,但是在实际使用时发现,在该工程中间新建Activiti Diagram,绘制好该图形之后,右键,新建单元测试,选择ju ...

  7. Metasploit_01_信息搜集技术

    信息搜集技术 姓名: 谈愈敏 学号: 20135220 日期: 2016.9.7 攻击机:135220-V.BT5, msf 靶 机:135220-V.W2k3_Sploitable 一.实验过程概述 ...

  8. 软件工程(QLGY2015)第二次作业点评(随机挑选20组点评)

    相关博文目录: 第一次作业点评 第二次作业点评 第三次作业点评 说明:随机挑选20组点评,大家可以看看blog名字,github项目名字,看看那种是更好的,可以学习,每个小组都会反应出一些问题,希望能 ...

  9. 招聘一个靠谱的ios

    1. 风格纠错题 修改方法有很多种,现给出一种做示例: 最终改为: 下面对具体修改的地方, 2. 什么情况使用 weak 关键字,相比 assign 有什么不同? 什么情况使用 weak 关键字? 1 ...

  10. javascript模块化详解

    模块化:每个模块只完成一个独立的功能,然后提供该功能的接口.模块间通过接口访问.模块中的(过程和数据)对于其它模块来说是私有的(不能访问修改) 原始人写法: function m1(){ //... ...