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. T - Posterized(贪心思维)

    Description Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked hi ...

  2. ACM_输出格式

    输出格式 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某水比参加了XX杯,但是他太水,所以三等都木有,所以他决定出一道水题水一 ...

  3. ACM_天涯若比邻(最小与最大相邻素数)

    天涯若比邻 Time Limit: 2000/1000ms (Java/Others) Problem Description: 一心想搞ACM的小G最近迷上了数论,特别对于跟“素数”相关的问题特别有 ...

  4. asp.net ajax get post 中文乱码解决办法

    前台: var username = $("#UserName").val(); var tel = $("#tel").val(); var yzm = $( ...

  5. Scala-基础-函数(1)

    import junit.framework.TestCase //函数(1) class Demo5 extends TestCase { def testDemo(){ println(" ...

  6. Python之pandas数据加载、存储

    Python之pandas数据加载.存储 0. 输入与输出大致可分为三类: 0.1 读取文本文件和其他更好效的磁盘存储格式 2.2 使用数据库中的数据 0.3 利用Web API操作网络资源 1. 读 ...

  7. 基于SOC方案的嵌入式开发-远程定时设备

    Soc方案实现简单的定时开关灯 http://club.gizwits.com/forum.php?mod=viewthread&tid=7787&highlight=%E5%AE%9 ...

  8. C++(变量类型-深入)

    变量类型 变量其实只不过是程序可操作的存储区的名称.C++ 中每个变量都有指定的类型,类型决定了变量存储的大小和布局,该范围内的值都可以存储在内存中,运算符可应用于变量上. 变量的名称可以由字母.数字 ...

  9. vue路由传参(学习心得)

    如果组件通过query来传递num参数为1,相当与在 url 地址后面拼接参数 <template> <div> <h3>首页</h3> <rou ...

  10. Error parsing D:\sdkforas\android-sdk-windows\system-images\android-22\android-wear\x86\devices.xml

    今天在工作过程中向Android Studio中导入一个项目,最后运行出现如下错误: Cannot reload AVD list: cvc-enumeration-valid: Value '280 ...