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. TrueType, OpenType, PCL和PostScript字体版本nterleaved 2 of 5 Barcode Font Advantage Package

    Interleaved 2 of 5 Barcode Font Advantage Package包含了TrueType, OpenType, PCL和PostScript字体版本. 提供了超过30个 ...

  2. MATLAB中mexFunction函数的接口规范(转载)

    MEX文件的调用极为方便,其调用方式与MATALAB的内建函数完全相同,只需要在命令窗口内输入对应的文件名称即可. C语言MEX程序代码文件有计算子例程(Computational routine)和 ...

  3. Python File I/O

    File is a named location on disk to store related information. It is used to permanently store data ...

  4. JVM-class文件完全解析-类索引,父类索引和索引集合

    类索引,父类索引和接口索引集合 前面介绍了class文件,从头开始的魔数,次版本号,主版本号,常量池入口,常量池,访问标志.那么再接下来的就是用来确定这个类的继承关系的类索引,父类索引和接口索引集合这 ...

  5. python解无忧公主的数学时间编程题001.py

    python解无忧公主的数学时间编程题001.py """ python解无忧公主的数学时间编程题001.py http://mp.weixin.qq.com/s?__b ...

  6. 根据username查找user

    返回的是一个list<User>,不过验证密码的时候,要求返回是一个user对象,如果用uniqueresult,这个是过时的方法,如果用getResultList 会得到一个列表,get ...

  7. Mvc5 Html.EditorFor

    如果对缺省的样子不满意, 可以有模板,寻寻觅觅,摸索出 在Views\Shared\EditorTemplates下创建String.cshtml 必须的是EditorTemplates文件夹 @{ ...

  8. 0125 多线程 继承Thread 练习

    //定义一个继承Thread类的类,并覆盖run()方法,在run()方法中每隔100毫秒打印一句话public class Csh extends Thread{ public void run() ...

  9. Android 对 properties文件的读写操作

    -. 放在res中的properties文件的读取,例如对放在assets目录中的setting.properties的读取:PS:之所以这里只是有读取操作,而没有写的操作,是因为我发现不能对res下 ...

  10. druid连接池配置

    本人使用的是springMVC框架,以下是我的配置: step1,配置数据源(applicationContext-resource.xml中): <bean id="cc_ds&qu ...