poj 1523 SPF 求割点以及删除该割点后联通块的数量
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7136 | Accepted: 3255 |
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
Source
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = ;
const int MAXM = ;
struct Edge
{
int to,next;
bool cut;//是否为桥的标记
} edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN];
int Index,top;
bool Instack[MAXN];
bool cut[MAXN];
int add_block[MAXN];//删除一个点后增加的连通块
int bridge;
void addedge(int u,int v)
{
edge[tot].to = v;
edge[tot].next = head[u];
edge[tot].cut = false;
head[u] = tot++;
}
void Tarjan(int u,int pre)
{
int v;
Low[u] = DFN[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for(int i = head[u]; i != -; i = edge[i].next)
{
v = edge[i].to;
if(v == pre)continue;
if( !DFN[v] )
{
son++;
Tarjan(v,u);
if(Low[u] > Low[v])Low[u] = Low[v];
if(Low[v] > DFN[u])
{
bridge++;
edge[i].cut = true;
edge[i^].cut = true;
}
if(u != pre && Low[v] >= DFN[u])//不是树根
{
cut[u] = true;
add_block[u]++;
}
}
else if( Low[u] > DFN[v])
Low[u] = DFN[v];
}
//树根,分支数大于1
if(u == pre && son > )
cut[u] = true;
if(u == pre)
add_block[u] = son - ;
Instack[u] = false;
top--;
}
void solve(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,,sizeof(Instack));
memset(add_block,,sizeof(add_block));
memset(cut,false,sizeof(cut));
Index = top = ;
int cnt = ;//原来的连通块数
for(int i = ; i <= N; i++)
if( !DFN[i] )
{
Tarjan(i,i);//找割点调用必须是Tarjan(i,i)
cnt++;
}
int ans = ;
bool flag=true;
for(int i = ; i <= N; i++){
if(cut[i]==true){
flag=false;
printf(" SPF node %d leaves %d subnets\n",i,add_block[i]+);
}
} if(flag)
printf(" No SPF nodes\n");
puts("");
}
void init()
{
tot = ;
memset(head,-,sizeof(head));
}
int main()
{
int n,m;
int u,v;
int cas=;
while(scanf("%d",&u)!=EOF)
{
cas++;
if(u==)
break;
init();
scanf("%d",&v);
addedge(u,v);
addedge(v,u);
n=max(u,v);
while(scanf("%d",&u)!=EOF){
if(u==)
break;
scanf("%d",&v);
addedge(u,v);
addedge(v,u);
int temp=max(u,v);
n=max(temp,n);
}
printf("Network #%d\n",cas);
solve(n);
}
return ;
}
poj 1523 SPF 求割点以及删除该割点后联通块的数量的更多相关文章
- POJ 1523 SPF 求割点的好(板子)题!
题意: 给个无向图,问有多少个割点,对于每个割点求删除这个点之后会产生多少新的点双联通分量 题还是很果的 怎么求割点请参考tarjan无向图 关于能产生几个新的双联通分量,对于每个节点u来说,我们判断 ...
- 【UVA10765】Doves and bombs (BCC求割点后联通块数量)
题目: 题意: 给了一个联通无向图,现在问去掉某个点,会让图变成几个联通块? 输出的按分出的从多到小,若相等,输出标号从小到大.输出M个. 分析: BCC求割点后联通块数量,Tarjan算法. 联通块 ...
- 分别利用并查集,DFS和BFS方法求联通块的数量
联通块是指给定n个点,输入a,b(1<=a,b<=n),然后将a,b连接,凡是连接在一起的所有数就是一个联通块: 题意:第一行输入n,m,分别表示有n个数,有输入m对连接点,以下将要输入m ...
- POJ 1523 SPF tarjan求割点
SPF Time Limit: 1000MS Memory Limit ...
- poj 1523 SPF(tarjan求割点)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- POJ 1523 SPF 割点 Tarjan
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9317 Accepted: 4218 Description C ...
- POJ 1523 SPF (去掉割点能形成联通块的个数)
思路:使用tarjan算法求出割点,在枚举去掉每一个割点所能形成的联通块的个数. 注意:后来我看了下别的代码,发现我的枚举割点的方式是比较蠢的方式,我们完全可以在tarjan过程中把答案求出来,引入一 ...
- zoj 1119 /poj 1523 SPF
题目描述:考虑图8.9中的两个网络,假定网络中的数据只在有线路直接连接的2个结点之间以点对点的方式传输.一个结点出现故障,比如图(a)所示的网络中结点3出现故障,将会阻止其他某些结点之间的通信.结点1 ...
随机推荐
- 2017微软骇客马拉松精彩大回Fun:不一样的Hacker,一Young的Cool
丹棱君有话说:一年一度激动人心的骇客马拉松大会结束了!这场内部创意大比拼硕果累累,丹棱君准备好了 6 组 Cool 骇客的别 Young 作品——沉浸式销售工具如何能守得“云”开见月明?“骇客马拉松超 ...
- Python之查询最新的文件
import os # 定义文件的目录 result_dir = r'E:\python\测试报告' lists = os.listdir(result_dir) # 重新按时间对目录下的文件进行排序 ...
- HDU 4283 You Are the One (区间DP,经典)
题意: 某校举行一场非诚勿扰,给定一个出场序列,表示n个人的屌丝值,如果他是第k个出场的,他的不满意度为(k-1)*diao[i].为了让所有人的屌丝值之和更小,导演设置一个栈,可以将部分人装进栈中, ...
- 【转载】UWP应用设置和文件设置:科普
数据有两个基本的分类,应用数据和用户数据,而用户数据则为由用户拥有的数据,如文档,音乐或电子邮件等,下面将大致的介绍一下应用数据的基本操作. 应用数据:应用数据包含APP的状态信息(如运行时状态,用户 ...
- Array - Merge Sorted Array
/** * 将nums2中的值合并入nums1,使其仍然有序 * 可以任务nums1的长度>=m+n * @param nums1 已排序数组 * @param m nums1数组已初始化的数目 ...
- 访问URI地址
//发送消息到服务器 public string HttpConnectToServer(string ServerPage) { byte[] dataArray = Encoding.Defaul ...
- 接口的多态使用; 接口应用实例:U盘、打印机可以使用共同的USB接口,插入到电脑上实现各自的功能。
接口的多态使用 接口应用实例:U盘.打印机可以使用共同的USB接口,插入到电脑上实现各自的功能.
- Framework的简单创建
如果你想将你开发的控件与别人分享,一种方法是直接提供源代码文件.然而,这种方法并不是很优雅.它会暴露所有的实现细节,而这些实现你可能并不想开源出来.此外,开发者也可能并不想看到你的所有代码,因为他们可 ...
- iOS8之后,UITableViewRowAction实现滑动多个按钮
#pragma mark - View lifeCycle - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = ...
- 学习笔记(三): Generalization/Overfitting/Validation
目录 Generalization: Peril of Overfitting Low loss, but still a bad model? How Do We Know If Our Mod ...