poj 1523 SPF【点双连通求去掉割点后bcc个数】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7246 | Accepted: 3302 |
Description
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
Output
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个数】的更多相关文章
- poj 2117 Electricity【点双连通求删除点后最多的bcc数】
Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4727 Accepted: 1561 Descr ...
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
- POJ 3177 边双连通求连通量度的问题
这道题的总体思路就是找到连通量让它能够看作一个集合,然后找这个集合的度,度数为1的连通量为k,那么需要添加(k+1)/2条边才可以保证边双连通 这里因为一个连通量中low[]大小是相同的,所以我们用a ...
- POJ - 1523 SPF
题目要求割顶集,并且还要求出去掉割顶之后剩下的图连通数目. tarjan算法求出割顶后直接枚举就可以了吧. 一开始想到利用iscut[u]的次数也就是点u被判定为割顶的次数求连通分量数,还有利用与结点 ...
- poj 3694 Network 边双连通+LCA
题目链接:http://poj.org/problem?id=3694 题意:n个点,m条边,给你一个连通图,然后有Q次操作,每次加入一条边(A,B),加入边后,问当前还有多少桥,输出桥的个数. 解题 ...
- POJ 1523 SPF (无向图割点)
<题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...
- poj 3469 Dual Core CPU【求最小割容量】
Dual Core CPU Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 21453 Accepted: 9297 ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)
poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...
随机推荐
- checking it the current os is a 32bit or 64bit version 检查操作系统是32位还是64位
) { Console.WriteLine("32bit os"); } ) { Console.WriteLine("64bit os"); }
- CoreBluetooth - 中心模式
BLE中心模式流程-coding BLE中心模式流程 - 1.建立中心角色 - 2.扫描外设(Discover Peripheral) - 3.连接外设(Connect Peripheral) - 4 ...
- C# const和statci readonly区别
1.const 是属于编译时的变量,它定义的常量是在对象初始化时赋值,以后不能改变他的值. 它适用于两种场景:1.取值永久不变(比如圆周率.一天包含的小时数.地球的半径等) 2.对程序性能要求非常苛 ...
- Linux数组array基础
Linux数组array基础[${a[*]}和$a的区别] Bash中,数组变量的赋值有两种方法: (1) name = (value1 ... valuen) 此时下标从0开始 (2) name[i ...
- Spring 数据源配置一:单一数据源
最近遇到一个项目,需要访问都多个数据源,并且数据库是不同厂商(mysql, sqlserver). 所以对此做了一些研究,这里咱们采用渐进的方式来展开,先谈谈单一数据源配置.(稍后有时间会陆续补充其 ...
- jQuery滑动导航菜单
js: $(function(){ $("ul.sub").parent().append("<span></span>"); $(&q ...
- ***PHP请求服务curl以及json的解析
对于thinkphp框架,相信每一个php开发者都会有了解或者熟悉吧!前端很多都用的ajax的结合,前几天遇到了一个问题,就是请求另一个服务,也就是请求一个接口,然后对方返回一个json串,一开始对c ...
- mysql查看'datadir'目录
mysql查看创建的数据库的数据,包含表等存放的目录,可以输入下面指令查看: show variables like 'datadir'
- YIi 权限管理和基于角色的访问控制
验证和授权(Authentication and Authorization) 定义身份类 (Defining Identity Class) 登录和注销(Login and Logout) 访问控制 ...
- Objective-c Category(类别)
NSStringUtilities.h: #import <Foundation/Foundation.h> @interface NSString(Utilities) -(BOOL) ...