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

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 题意:求去掉割点之后 整个图分为多少个bcc 输出割点的编号以及去掉割点后bcc个数 割点:如果在无向图G中去掉一个顶点(自然同时去掉与该顶点相关联的所有边)后图的连通分支数增加,则称该顶点为G的割点 节点是割点的条件满足1或者2:
1、节点是根节点并且这个根节点有两个以及两个以上的子节点
2、节点不是根节点 满足dfn[u]<=low[v]; 去掉割点后bcc增加的数目:
1:如果割点是根节点它的子节点数目为son去掉之后bcc增加son个
2:割点不是根节点它的子节点数目为son个去掉之后 bcc增加son+1个
#include<stdio.h>
#include<string.h>
#include<stack>
#include<algorithm>
#define MAX 2100
#define INF 0x7fffff
using namespace std;
int dfn[MAX],low[MAX];
int dfsclock,ebccnt;
int addbcc[MAX];//记录去掉割点后bcc个数
int head[MAX],ans;
int iscut[MAX];//记录是否是割点
struct node
{
int beg,end,next;
}edge[MAX];
void init()
{
ans=0;
memset(head,-1,sizeof(head));
}
void add(int u,int v)
{
edge[ans].beg=u;
edge[ans].end=v;
edge[ans].next=head[u];
head[u]=ans++;
}
void tarjan(int u,int fa)
{
int i,v;
dfn[u]=low[u]=++dfsclock;
int son=0;//记录子节点数目
for(i=head[u];i!=-1;i=edge[i].next)
{
v=edge[i].end;
if(!dfn[v])
{
son++;
tarjan(v,u);
low[u]=min(low[u],low[v]);
if(dfn[u]<=low[v])//是割点,先不考虑是不是根节点
{
addbcc[u]++;//这是割点的一个子节点,bcc数目加1
iscut[u]=1;
}
}
else
low[u]=min(dfn[v],low[u]);
}
if(fa<0&&son<2)//不是根节点
{
iscut[u]=0;
addbcc[u]=0;
}
if(fa<0&&son>1)//是根节点
{
iscut[u]=1;
addbcc[u]=son-1;//这里当是根节点时去掉割点bcc数目为子节点数目son
//但是因为上边我们for循环中求bcc时全部当做非根节点求这样
//其非根节点割点去掉之后bcc个数 为son+1,为了最后输出时统一加1
//这里我们让 addbcc[u]=son-1;
}
}
void find(int l,int r)
{
dfsclock=0;
memset(low,0,sizeof(low));
memset(dfn,0,sizeof(dfn));
memset(addbcc,0,sizeof(addbcc));
memset(iscut,0,sizeof(iscut));
for(int i=l;i<=r;i++)
{
if(!dfn[i])
tarjan(i,-1);
}
}
int main()
{
int n,m,j,i,a,b;
int Max,Min;
int k=0;
while(1)
{
int t=0;
Max=-1;Min=INF;
init();
while(scanf("%d",&a)&&a!=0)
{
t++;
scanf("%d",&b);
Max=max(Max,max(a,b));
Min=min(Min,min(a,b));
add(a,b);
add(b,a);
}
if(a==0&&t==0)
break;
find(Min,Max);
int flag=0;
printf("Network #%d\n",++k);
for(i=Min;i<Max;i++)
{
if(iscut[i])
{
flag=1;
printf(" SPF node %d leaves %d subnets\n",i,addbcc[i]+1);
}
}
if(!flag)
printf(" No SPF nodes\n");
printf("\n");
}
return 0;
}

  

poj 1523 SPF【点双连通求去掉割点后bcc个数】的更多相关文章

  1. poj 2117 Electricity【点双连通求删除点后最多的bcc数】

    Electricity Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4727   Accepted: 1561 Descr ...

  2. poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】

    Road Construction Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10141   Accepted: 503 ...

  3. POJ 3177 边双连通求连通量度的问题

    这道题的总体思路就是找到连通量让它能够看作一个集合,然后找这个集合的度,度数为1的连通量为k,那么需要添加(k+1)/2条边才可以保证边双连通 这里因为一个连通量中low[]大小是相同的,所以我们用a ...

  4. POJ - 1523 SPF

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

  5. poj 3694 Network 边双连通+LCA

    题目链接:http://poj.org/problem?id=3694 题意:n个点,m条边,给你一个连通图,然后有Q次操作,每次加入一条边(A,B),加入边后,问当前还有多少桥,输出桥的个数. 解题 ...

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

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

  7. poj 3469 Dual Core CPU【求最小割容量】

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 ...

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

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

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

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

随机推荐

  1. 华为机试题——数组排序,且奇数存在奇数位置,偶数存在偶数位置

    题目要求很简单,就是给你一个数组,对它进行排序,并且排序后,奇数要放在奇数的位置上,偶数要放在偶数的位置上,如果不满足这个规则的话就在数组上填充0 实现代码如下,文中值得注意的一点就是如何判读这个数字 ...

  2. 几个不常见但非常出色的 .NET 开源库

    NLog NLog 目前最为出色的 .NET 日志库,非常容易配置,且极具灵活性.最重要的是与 log4net 相比,NLog 的开发很活跃.顺带提一句,NLog 完全兼容 Mono. Mono.Ce ...

  3. 浅谈 iOS 之 Crash log 符号化

    其实,对于做移动 APP 开发的同学来说,质量和体验都是同等重要的.一个 APP 应用如果经常「闪退」,是产品质量很差的一个体现,那么用户体验就更不用再提了. *** 上面是笔者截取的国外一家公司对用 ...

  4. ASP.NET MVC中HttpContext, HttpContextBase, HttpContextWrapper联系

    ttpContext HttpContext是最原始的ASP.NET Context. MVC的目的之一是能够单元测试.HttpContext没有base class,并且不是virtual,所以不能 ...

  5. [Gauss]POJ1681 Painter's Problem

    和POJ1222(分析)完全相同 题意也类似, 可以涂自己以及上下左右五个位置的颜色 问几次能全部涂色 不能输出inf 01方程组 用异或来求解就好了 ][]; // 增广矩阵 ]; // 解 ]; ...

  6. bitset学习小记

    Cplusplus官网的资料: http://www.cplusplus.com/reference/bitset/bitset/ http://www.cplusplus.com/reference ...

  7. What's this?(js)

    What's this? 由于运行期绑定的特性,JavaScript 中的 this 含义非常多,它可以是全局对象.当前对象或者任意对象,这完全取决于函数的调用方式 随着函数使用场合的不同,this的 ...

  8. 图像色彩空间YUV和RGB的差别

    http://blog.csdn.net/scg881008/article/details/7168637 假如是200万像素的sensor,是不是RGB一个pixel是2M,YUV是1M? 首先, ...

  9. INCOIN Importing Multilingual Items (Doc ID 278126.1)

    APPLIES TO: Oracle Inventory Management - Version: 11.5.9 to 11.5.10.CU2 - Release: 11.5 to 11.5 GOA ...

  10. Oracle系列之游标

    涉及到表的处理请参看原表结构与数据  Oracle建表插数据等等 游标: 1.目的 解决“ select * ”返回空.多行记录问题 但凡select,就可能多行结果集,也就需要用游标 2.原理 多行 ...