SPF

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8114   Accepted: 3716

Description

Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on the left would prevent some of the still available nodes from communicating with each other. Nodes 1 and 2 could still communicate with each other as could nodes 4 and 5, but communication between any other pairs of nodes would no longer be possible.

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

The input will contain the description of several networks. A network description will consist of pairs of integers, one pair per line, that identify connected nodes. Ordering of the pairs is irrelevant; 1 2 and 2 1 specify the same connection. All node numbers will range from 1 to 1000. A line containing a single zero ends the list of connected nodes. An empty network description flags the end of the input. Blank lines in the input file should be ignored.

Output

For each network in the input, you will output its number in the file, followed by a list of any SPF nodes that exist.

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(割点)的更多相关文章

  1. HDU4738 tarjan割边|割边、割点模板

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4738 坑点: 处理重边 图可能不连通,要输出0 若求出的结果是0,则要输出1,因为最少要派一个人 #inc ...

  2. ACM/ICPC 之 Dinic+枚举最小割点集(可做模板)(POJ1815)

    最小割的好题,可用作模板. //Dinic+枚举字典序最小的最小割点集 //Time:1032Ms Memory:1492K #include<iostream> #include< ...

  3. 洛谷P3388 【模板】割点

    给出一个n个点,m条边的无向图,求图的割点. u是cut vertex的两个条件: 1.存在v使v及其所有后代没有反向边连回u的祖先 2.u是根且有两个以上子节点 dfs一遍 low[u]是u及其后代 ...

  4. 【UOJ#67】新年的毒瘤 Tarjan 割点

    #67. 新年的毒瘤 UOJ直接黏贴会炸...    还是戳这里吧: http://uoj.ac/problem/67#tab-statement Solution 看到这题的标签就进来看了一眼. 想 ...

  5. hihoCoder 1183 连通性一·割边与割点(Tarjan求割点与割边)

    #1183 : 连通性一·割边与割点 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 还记得上次小Hi和小Ho学校被黑客攻击的事情么,那一次攻击最后造成了学校网络数据的丢 ...

  6. {part1}DFN+LOW(tarjan)割点

    什么是jarjan? 1)求割点 定义:在无向连通图中,如果去掉一个点/边,剩下的点之间不连通,那么这个点/边就被称为割点/边(或割顶/桥). 意义:由于割点和割边涉及到图的连通性,所以快速地求出割点 ...

  7. 图的割点 | | jzoj【P1230】 | | gdoi | |备用交换机

    写在前面:我真的不知道图的割点是什么.... 看见ftp图论专题里面有个dfnlow的一个文档,于是怀着好奇的心情打开了这个罪恶的word文档,,然后就开始漫长的P1230的征讨战.... 图的割点是 ...

  8. 割点和桥---Tarjan算法

    使用Tarjan算法求解图的割点和桥. 1.割点 主要的算法结构就是DFS,一个点是割点,当且仅当以下两种情况:         (1)该节点是根节点,且有两棵以上的子树;         (2)该节 ...

  9. Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)【转】【修改】

    一.基本概念: 1.割点:若删掉某点后,原连通图分裂为多个子图,则称该点为割点. 2.割点集合:在一个无向连通图中,如果有一个顶点集合,删除这个顶点集合,以及这个集合中所有顶点相关联的边以后,原图变成 ...

随机推荐

  1. The 2014 ACM-ICPC Asia Regional Anshan Online

    [A]无向图的双联通子图计数.DP+状态压缩 [B]计算几何(点的旋转) [C]DP+状态压缩 [D]离散数学+DP (感觉可出) [E]概率DP [F]LCT模板题(-_-///LCT是啥!!!!) ...

  2. javadoc时候乱码-编码 GBK 的不可映射字符 - wqjsir的专栏 - 博客频道 - CSDN.NET

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  3. jquery如何判断元素是否被点击_百度知道

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <div id="parent"> <a id="a1" ...

  4. Nginx 负载均衡 后端 监控检测 nginx_upstream_check_module 模块的使用

    在使用nginx 的负载均衡 中,我们通常会使用到 Nginx 自带的 ngx_http_proxy_module 健康检测模块. ngx_http_proxy_module 自带的 健康检测模块参数 ...

  5. SQL 复习二(数据查询语言)

    1.1 数据查询语言 DQL就是数据查询语言,数据库执行DQL语句不会对数据进行改变,而是让数据库发送结果集给客户端. 语法: SELECT selection_list /*要查询的列名称*/ FR ...

  6. artTemplate-3.0(与项目实际结合)

    引入artTemplate.js <script type="text/javascript" src="${ctx}/assets/plugins/artTemp ...

  7. mysql trouble shooting---- 从库停止同步lock_wait_timeout_exceeded_try_restarting_transaction

    问题描述: 数据库从库停止同步. 问题分析: show slave status\G;(也可使用show full processlist) 显示 某个update语句出错,Lock wait tim ...

  8. JQuery实现超链接鼠标提示效果

    一.第一种方法用Jquery<p><a href="http://www.nowamagic.net/" class="tooltip" ti ...

  9. Mac快速查看某条命令的版本和存放的位置(ls -l `which mvn`)

    输入: ls -l `which mvn` 如图:

  10. MySQL 启动、关闭、选择数据库等命令

    一.MySQL服务的启动和停止 1.net 命令来启动或停止mysql服务 net stop mysql(mysql是指你真正装的服务,如果装的是 mysql5,必须写成 net stop mysql ...