POJ 1523 SPF 割点 Tarjan
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 9317 | Accepted: 4218 |
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<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 1009
#define N 100
/*
求割点的个数 和割点被去掉之后联通快的个数
//删除割点u产生的连通数目为:u所在的连通分量数目+与u所连接的割边的数目+1(边:fa->u)
*/
struct edge
{
//edge(int _t,int _next):to(_t),next(_next){}
int to, next;
};
edge E[MAXN * MAXN];
int index, dfn[MAXN], low[MAXN], s[MAXN], head[MAXN], cnt, Max, cas = , root;
bool flag;
void Init()
{
index = ;
Max = -;
cnt = ;
flag = false;
memset(head, -, sizeof(head));
memset(dfn, , sizeof(dfn));
memset(s, , sizeof(s));
memset(low, , sizeof(low));
}
void add_edge(int u, int v)
{
E[cnt].to = v;
E[cnt].next = head[u];
head[u] = cnt++;
Max = max(max(u, v), Max);
} void tarjan(int pre, int u)
{
int son = ;
low[u] = dfn[u] = ++index;
for (int i = head[u]; i != -; i = E[i].next)
{
int v = E[i].to;
if (!dfn[v])
{
tarjan(u, v);
son++;
low[u] = min(low[v], low[u]);
if ((u == root&&son > ) || (u != root&&low[v] >= dfn[u]))
{
flag = true;
s[u]++;
}
}
else if (v != pre)
low[u] = min(low[u], dfn[v]);
}
} int main()
{
int f, t;
while ()
{
Init();
while (scanf("%d",&f), f)
{
scanf("%d", &t);
add_edge(f, t);
add_edge(t, f);
}
if (Max == -)
break;
root = Max;
tarjan(-, Max);
printf("Network #%d\n",cas++);
if (!flag)
{
printf(" No SPF nodes\n");
}
else
{
for (int i = ; i <= Max; i++)
if (s[i] > )
printf(" SPF node %d leaves %d subnets\n", i, s[i] + );
}
printf("\n");
}
}
POJ 1523 SPF 割点 Tarjan的更多相关文章
- POJ 1523 SPF 割点与桥的推断算法-Tarjan
题目链接: POJ1523 题意: 问一个连通的网络中有多少个关节点,这些关节点分别能把网络分成几部分 题解: Tarjan 算法模板题 顺序遍历整个图,能够得到一棵生成树: 树边:可理解为在DFS过 ...
- poj 1523 SPF(tarjan求割点)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- POJ 1523 SPF (割点,连通分量)
题意:给出一个网络(不一定连通),求所有的割点,以及割点可以切分出多少个连通分量. 思路:很多种情况. (1)如果给的图已经不是连通图,直接“ No SPF nodes”. (2)求所有割点应该不难 ...
- POJ 1523 SPF tarjan求割点
SPF Time Limit: 1000MS Memory Limit ...
- Electricity POJ - 2117 + SPF POJ - 1523 去除割点后求强连通分量个数问题
Electricity POJ - 2117 题目描述 Blackouts and Dark Nights (also known as ACM++) is a company that provid ...
- zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)
poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- POJ 1523 SPF (去掉割点能形成联通块的个数)
思路:使用tarjan算法求出割点,在枚举去掉每一个割点所能形成的联通块的个数. 注意:后来我看了下别的代码,发现我的枚举割点的方式是比较蠢的方式,我们完全可以在tarjan过程中把答案求出来,引入一 ...
- POJ 1523 SPF (无向图割点)
<题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...
随机推荐
- mydatepicker97 日历控件
官方教程: http://www.my97.net/
- ACM_天涯若比邻(最小与最大相邻素数)
天涯若比邻 Time Limit: 2000/1000ms (Java/Others) Problem Description: 一心想搞ACM的小G最近迷上了数论,特别对于跟“素数”相关的问题特别有 ...
- web项目无法部署到eclipse配置的本地tomcat
一.发现问题 在eclipse中新建Dynamic Web Project,配置好本地的tomcat并写好代码后选择Run on Server,但运行后发现在tomcat的安装目录下的webapps并 ...
- SQL在一张表中根据父ID获取所有的子ID
with a as ( select id,name,parentid from categories where id=53 union all select x.id,x.name,x.paren ...
- 实用and常用shell命令汇编
很久没写blog了,基本都在用 github和笔记.现在将一些常用的shell并且很使用的shell用法分享一下: 分行读取,切割,计数: cat product.txt | while read l ...
- python中os模块中文帮助
python中os模块中文帮助 python中os模块中文帮助文档文章分类:Python编程 python中os模块中文帮助文档 翻译者:butalnd 翻译于2010.1.7——2010.1.8 ...
- 轮播图-version1
实现目标 按'>'出现下一caption,按'<'出现上一caption 按下面的点到指定的caption 自动轮播 思路: 设置一个carousel容器,里面有carousel的每一张图 ...
- 【C++】智能指针简述(二):auto_ptr
首先,我要声明auto_ptr是一个坑!auto_ptr是一个坑!auto_ptr是一个坑!重要的事情说三遍!!! 通过上文,我们知道智能指针通过对象管理指针,在构造对象时完成资源的分配及初始化,在析 ...
- PHP7 上传文件报错 Internal Server Error 解决方法
打开Apache配置httpd.conf.在最后添加FcgidMaxRequestLen指令一个足够大的值(以字节为单位),例如 FcgidMaxRequestLen 100000000 最后重新启动 ...
- SqlBulkCopy实现大批量数据导入
//自增列重新生成:SqlBulkCopy bc = new SqlBulkCopy(conn) //自增列保留原值:SqlBulkCopy bc = new SqlBulkCopy(conn,Sql ...