POJ1556(割点)
SPF
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8114 | Accepted: 3716 |
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
题意:求割点和去掉割点后的连通块
//2016.9.16
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 1005 using namespace std; struct edge
{
int tar;
edge *nex;
}*head[N], *eg, edges[N*N]; int fl[N]; void add(int a, int b)
{
eg->tar = b;
eg->nex = head[a];
head[a] = eg++;
} void dfs(int k, int x)
{
fl[k] = x;
for(edge *i = head[k]; i != NULL; i = i->nex)
{
if(i->tar==x || fl[i->tar]==x)continue;
dfs(i->tar, x);
}
} int main()
{
int kase = , a, b;
while()
{
memset(head, , sizeof(head));
eg = edges;
int n = ;//n用来记录有多少个节点
while(scanf("%d", &a)&&a)
{
scanf("%d", &b);
n = max(n, max(a, b));
a--, b--;//编号从0开始,a、b都减1
add(a, b);//无向图
add(b, a);
}
if(!n)return ;//如果有0个节点,返回
if(kase)printf("\n");
printf("Network #%d\n", ++kase);
bool fg = false;
memset(fl, -, sizeof(fl));
for(int i = ; i < n; i++)
{
if(head[i] == NULL)continue;
int cnt = ;
for(int j = ; j < n; j++)
{
if(i == j)continue;
if(head[j] == NULL)continue;
if(fl[j] < i)
{
cnt++;
dfs(j, i);
}
}
if(cnt > )
{
printf(" SPF node %d leaves %d subnets\n", i+, cnt);
fg = true;
}
}
if(!fg)printf(" No SPF nodes\n");
} return ;
}
POJ1556(割点)的更多相关文章
- HDU4738 tarjan割边|割边、割点模板
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4738 坑点: 处理重边 图可能不连通,要输出0 若求出的结果是0,则要输出1,因为最少要派一个人 #inc ...
- ACM/ICPC 之 Dinic+枚举最小割点集(可做模板)(POJ1815)
最小割的好题,可用作模板. //Dinic+枚举字典序最小的最小割点集 //Time:1032Ms Memory:1492K #include<iostream> #include< ...
- 洛谷P3388 【模板】割点
给出一个n个点,m条边的无向图,求图的割点. u是cut vertex的两个条件: 1.存在v使v及其所有后代没有反向边连回u的祖先 2.u是根且有两个以上子节点 dfs一遍 low[u]是u及其后代 ...
- 【UOJ#67】新年的毒瘤 Tarjan 割点
#67. 新年的毒瘤 UOJ直接黏贴会炸... 还是戳这里吧: http://uoj.ac/problem/67#tab-statement Solution 看到这题的标签就进来看了一眼. 想 ...
- hihoCoder 1183 连通性一·割边与割点(Tarjan求割点与割边)
#1183 : 连通性一·割边与割点 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 还记得上次小Hi和小Ho学校被黑客攻击的事情么,那一次攻击最后造成了学校网络数据的丢 ...
- {part1}DFN+LOW(tarjan)割点
什么是jarjan? 1)求割点 定义:在无向连通图中,如果去掉一个点/边,剩下的点之间不连通,那么这个点/边就被称为割点/边(或割顶/桥). 意义:由于割点和割边涉及到图的连通性,所以快速地求出割点 ...
- 图的割点 | | jzoj【P1230】 | | gdoi | |备用交换机
写在前面:我真的不知道图的割点是什么.... 看见ftp图论专题里面有个dfnlow的一个文档,于是怀着好奇的心情打开了这个罪恶的word文档,,然后就开始漫长的P1230的征讨战.... 图的割点是 ...
- 割点和桥---Tarjan算法
使用Tarjan算法求解图的割点和桥. 1.割点 主要的算法结构就是DFS,一个点是割点,当且仅当以下两种情况: (1)该节点是根节点,且有两棵以上的子树; (2)该节 ...
- Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)【转】【修改】
一.基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成 ...
随机推荐
- 黑科技--位集--bitset
自从上次网赛发现这么个东西之后,深深地感受到了bitset的强大,0.0. 正常的bool占用1字节空间,bitset可以把这个缩到1bit,空间上8倍优化.正常用起来可能会跟位运算状态压缩类似,但是 ...
- Java面向对象设计
1.少了程序入口会在输出的地方报这个错: Syntax error, insert "... VariableDeclaratorId" to complete FormalPar ...
- 【转】聊聊HTTPS和SSL/TLS协议
要说清楚 HTTPS 协议的实现原理,至少需要如下几个背景知识.1. 大致了解几个基本术语(HTTPS.SSL.TLS)的含义2. 大致了解 HTTP 和 TCP 的关系(尤其是“短连接”VS“长连接 ...
- Android控件系列之RadioButton&RadioGroup
学习目的: 1.掌握在Android中如何建立RadioGroup和RadioButton 2.掌握RadioGroup的常用属性 3.理解RadioButton和CheckBox的区别 4.掌握Ra ...
- JNI 中文字符串传递(转)
源:JNI 中文字符串传递 因为项目编码中通过JNI传递中文字符时出现乱码问题,特搜集了相关资料,整理如下: java内部是使用16bit的unicode编码(UTF-16)来表示字符串的,无论中文英 ...
- 使用Cookie记住用户名和密码
Login.jsp <form name = "f1" method="get" action="servlet/LoginServlet&qu ...
- Delphi 常用函数(数学函数)round、trunc、ceil和floor
源:Delphi 常用函数(数学函数)round.trunc.ceil和floor Delphi 常用函数(数学) Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里 ...
- IOS开发-UI学习-UISlider(滑动条)的使用
滑动条即UISlider,是我们常见的软件中设置音量,亮度等的滑条,初始化及基本设置如下: // 新建滑动条 UISlider *slider = [[UISlider alloc]initWithF ...
- iOS数据存储
[reference]http://www.infoq.com/cn/articles/data-storage-in-ios 谈到数据储存,首先要明确区分两个概念,数据结构和储存方式.所谓数据结构就 ...
- Zju1290 Word-Search Wonder(http://begin.lydsy.com/JudgeOnline/problem.php?id=2768)
2768: Zju1290 Word-Search Wonder Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit] ...