SPF
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9317   Accepted: 4218

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

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 1009
#define N 100
/*
求割点的个数 和割点被去掉之后联通快的个数
//删除割点u产生的连通数目为:u所在的连通分量数目+与u所连接的割边的数目+1(边:fa->u)
*/
struct edge
{
//edge(int _t,int _next):to(_t),next(_next){}
int to, next;
};
edge E[MAXN * MAXN];
int index, dfn[MAXN], low[MAXN], s[MAXN], head[MAXN], cnt, Max, cas = , root;
bool flag;
void Init()
{
index = ;
Max = -;
cnt = ;
flag = false;
memset(head, -, sizeof(head));
memset(dfn, , sizeof(dfn));
memset(s, , sizeof(s));
memset(low, , sizeof(low));
}
void add_edge(int u, int v)
{
E[cnt].to = v;
E[cnt].next = head[u];
head[u] = cnt++;
Max = max(max(u, v), Max);
} void tarjan(int pre, int u)
{
int son = ;
low[u] = dfn[u] = ++index;
for (int i = head[u]; i != -; i = E[i].next)
{
int v = E[i].to;
if (!dfn[v])
{
tarjan(u, v);
son++;
low[u] = min(low[v], low[u]);
if ((u == root&&son > ) || (u != root&&low[v] >= dfn[u]))
{
flag = true;
s[u]++;
}
}
else if (v != pre)
low[u] = min(low[u], dfn[v]);
}
} int main()
{
int f, t;
while ()
{
Init();
while (scanf("%d",&f), f)
{
scanf("%d", &t);
add_edge(f, t);
add_edge(t, f);
}
if (Max == -)
break;
root = Max;
tarjan(-, Max);
printf("Network #%d\n",cas++);
if (!flag)
{
printf(" No SPF nodes\n");
}
else
{
for (int i = ; i <= Max; i++)
if (s[i] > )
printf(" SPF node %d leaves %d subnets\n", i, s[i] + );
}
printf("\n");
}
}

POJ 1523 SPF 割点 Tarjan的更多相关文章

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

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

  2. poj 1523 SPF(tarjan求割点)

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

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

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

  4. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

  5. Electricity POJ - 2117 + SPF POJ - 1523 去除割点后求强连通分量个数问题

    Electricity POJ - 2117 题目描述 Blackouts and Dark Nights (also known as ACM++) is a company that provid ...

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

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

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

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

  8. POJ 1523 SPF (去掉割点能形成联通块的个数)

    思路:使用tarjan算法求出割点,在枚举去掉每一个割点所能形成的联通块的个数. 注意:后来我看了下别的代码,发现我的枚举割点的方式是比较蠢的方式,我们完全可以在tarjan过程中把答案求出来,引入一 ...

  9. POJ 1523 SPF (无向图割点)

    <题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...

随机推荐

  1. 使用Redis存储Nginx+Tomcat负载均衡集群的Session

    配置Tomcat的session共享可以有三种解决方案: 第一种是以负载均衡服务器本身提供的session共享策略,每种服务期的配置是不一样的并且nginx本身是没有的. 第二种是利用web容器本身的 ...

  2. java大数轻松过

    import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(S ...

  3. java 键盘输入多种方法

    转! 分类: java学习2012-11-04 09:58 8427人阅读 评论(1) 收藏 举报 一.java不像C中拥有scanf这样功能强大的函数,大多是通过定义输入输出流对象.常用的类有Buf ...

  4. 273 Integer to English Words 整数转换英文表示

    将非负整数转换为其对应的英文表示,给定的输入是保证小于 231 - 1 的.示例:123 -> "One Hundred Twenty Three"12345 -> & ...

  5. elastic-job 的简单使用

    说明:这个是使用2.1.5版本 elastic-job是当当开源的的的定时任务,使用也是很简单的,可以解决数据量的大的时候可以分片执行,多应用节点部署时候不会重复执行. 是通过zookeeper作为控 ...

  6. MySQL详解(18)-----------分页方法总结

    ---方法1: 直接使用数据库提供的SQL语句---语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT M,N---适应场景: 适用于数据量较少的情况(元组百/千 ...

  7. java树型结构的数据展现设计

    在做一个需求管理的页面时,需求的展现是不限层级树型结构,需求下还可以分拆任务,页面要展现的字段有20多个,而且需求采用通用表单设计,db采用大宽表存储,有一百多个字段.目前数据量不大,第一版采用普通的 ...

  8. Java获取一个文件夹内的所有文件(包括所有子文件夹内的)

    输入文件数组.文件夹路径 返回的文件在输入的文件数组中 private void getFiles(ArrayList<File> fileList, String path) { Fil ...

  9. CAD使用GetXData读数据(com接口)

    主要用到函数说明: MxDrawEntity::GetXData 返回实体的扩展数据. c#代码实现如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  10. CAD利用Select2得到所有实体(网页版)

    主要用到函数说明: IMxDrawSelectionSet::Select2 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARI ...