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, ...
随机推荐
- 用android-x86模拟器不能运行程序错误Tag:libc的问题
如果用的是x86的android模拟器,运行软件时一闪就关闭logcat中:类似:Fatal signal 11 (SIGSEGV) at 0x00000078 (code=1), thread 16 ...
- hdu 3480
斜率dp #include<cstdio> #include<cstring> #include<algorithm> #include<queue> ...
- 静态分析安全测试(SAST)优缺点探析
静态分析安全测试(SAST)是指不运行被测程序本身,仅通过分析或者检查源程序的语法.结构.过程.接口等来检查程序的正确性,那么采用静分析安全测试的方法有什么优缺点呢,且让小编给你说道说道. 许多公司都 ...
- 如何启动 SQL Server Agent(SQL Server 配置管理器)
如何启动 SQL Server Agent(SQL Server 配置管理器) SQL Server 2008 R2 其他版本 4(共 6)对本文的评价是有帮助 - 评价此主题 可以从 SQL S ...
- Android USB Host 与 HID 之通讯方法
Android USB Host与HID通讯,就目前Google Developer提供的方法有bulkTransfer()与controlTransfer(),看是简简单单的两个方法,要实现真正的通 ...
- ArcGIS Engine生成等值线(C#)
原文:ArcGIS Engine生成等值线(C#) 本文介绍c#写的利用ArcGIS Engine生成等值线的方法.c#写的根据雨量站的降雨量值内插出降雨量等值线的功能.做几点说明:根据离散点生成等值 ...
- 转载爱哥自定义View系列--Canvas详解
上面所罗列出来的各种drawXXX方法就是Canvas中定义好的能画什么的方法(drawPaint除外),除了各种基本型比如矩形圆形椭圆直曲线外Canvas也能直接让我们绘制各种图片以及颜色等等,但是 ...
- Android中改变dialog的显示的位置和大小
private void setDialogSize(Dialog dg) { Window dialogWindow = dg.getWindow(); WindowManager.LayoutPa ...
- QQ输入法个人设置
常用 按键 外观 词库 账户 高级
- 海量数据的二度人脉挖掘算法(Hadoop 实现)
最近做了一个项目,要求找出二度人脉的一些关系,就好似新浪微博的“你可能感兴趣的人” 中,间接关注推荐:简单描述:即你关注的人中有N个人同时都关注了 XXX . 在程序的实现上,其实我们要找的是:若 U ...