SPF
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7406   Accepted: 3363

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
题意:问将某个点删除可产生多少个连通分量。
思路:考察对tarjan算法原理理解,解释见代码。
#include"cstdio"
#include"cstring"
using namespace std;
const int MAXN=;
struct Edge{
int to,next;
}es[MAXN*];
int V,E;
int head[MAXN];
inline int max(int u,int v)
{
return u > v? u: v;
}
inline int min(int a,int b)
{
return a > b? b: a;
}
void add_edge(int u,int v)
{
es[E].to=v;
es[E].next=head[u];
head[u]=E++;
V=max(max(u,v),V);
}
bool flag;
int root;
int subnets[MAXN];
int index;
int dfn[MAXN],low[MAXN];
void tarjan(int u,int fa)
{
int son=;
dfn[u]=low[u]=++index;
for(int i=head[u];i!=-;i=es[i].next)
{
int v=es[i].to;
if(!dfn[v])
{
tarjan(v,u);
son++;
low[u]=min(low[u],low[v]);
if((u==root&&son>)||(u!=root&&dfn[u]<=low[v]))
{
flag=true;
subnets[u]++;
//u->v 该边导致u成为割点
//当dfn[u]==low[v]时u->v为返祖边,u、v处于同一双连通分量中
//当dfn[u]<low[v]时u->v为割边
//删除割点u产生的连通数目为:u所在的连通分量数目+与u所连接的割边的数目+1(边:fa->u)
}
}
else if(v!=fa) low[u]=min(low[u],dfn[v]);
}
}
int main()
{
int cas=;
int u,v;
while(true)
{
v=-;
index=;
memset(subnets,,sizeof(subnets));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(head,-,sizeof(head));
V=-,E=;
flag=false;
while(scanf("%d",&u)&&u)
{
scanf("%d",&v);
add_edge(u,v);
add_edge(v,u);
}
if(v==-) break;
root=V;
tarjan(root,-);
printf("Network #%d\n",++cas);
if(flag)
{
for(int i=;i<=V;i++)
{
if(subnets[i]>)
{
printf(" SPF node %d leaves %d subnets\n",i,subnets[i]+);//加上fa->u该边所连接的连通分量
}
}
}
else printf(" No SPF nodes\n");
printf("\n");
}
return ;
}

POJ1523(割点所确定的连用分量数目,tarjan算法原理理解)的更多相关文章

  1. 寻找图的强连通分量:tarjan算法简单理解

    1.简介tarjan是一种使用深度优先遍历(DFS)来寻找有向图强连通分量的一种算法. 2.知识准备栈.有向图.强连通分量.DFS. 3.快速理解tarjan算法的运行机制提到DFS,能想到的是通过栈 ...

  2. 有向图强连通分量的Tarjan算法

    有向图强连通分量的Tarjan算法 [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G ...

  3. 【转】有向图强连通分量的Tarjan算法

    原文地址:https://www.byvoid.com/blog/scc-tarjan/ [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly con ...

  4. 算法笔记_144:有向图强连通分量的Tarjan算法(Java)

    目录 1 问题描述 2 解决方案 1 问题描述 引用自百度百科: 如果两个顶点可以相互通达,则称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G是一个强连 ...

  5. 【转载】有向图强连通分量的Tarjan算法

    转载地址:https://www.byvoid.com/blog/scc-tarjan [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly conn ...

  6. 有向图强连通分量的Tarjan算法(转)

    [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G是一个强连通图.非强连通图有向图的极 ...

  7. 强连通分量的Tarjan算法

    资料参考 Tarjan算法寻找有向图的强连通分量 基于强联通的tarjan算法详解 有向图强连通分量的Tarjan算法 处理SCC(强连通分量问题)的Tarjan算法 强连通分量的三种算法分析 Tar ...

  8. 『图论』有向图强连通分量的Tarjan算法

    在图论中,一个有向图被成为是强连通的(strongly connected)当且仅当每一对不相同结点u和v间既存在从u到v的路径也存在从v到u的路径.有向图的极大强连通子图(这里指点数极大)被称为强连 ...

  9. 有向图强连通分量的Tarjan算法及模板

    [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强联通(strongly connected),如果有向图G的每两个顶点都强联通,称有向图G是一个强联通图.非强联通图有向 ...

随机推荐

  1. 2018年EMUI系统能力分论坛来啦

    为鼓励开发者创新,挖掘前沿创新能力的应用及服务,帮开发者打造爆款应用的同时丰富终端消费者的用户体验,由设立10亿激励基金耀星计划扶持的华为创新竞赛平台即将开启. 竞赛平台将滚动推出AI.HAG.AR. ...

  2. 关于erlang的-run 的启动参数

    在github上,关于erlang的一致性hash,有erlang-ryng和 hash_ring .在这里先聊下erlang-ryng这个. 在erlang-ryng的启动方式上,github上提供 ...

  3. 深入Asyncio(五)Event Loop

    Event Loop loop除了处理协程间的切换与结束时的异常捕捉,还要监听socket和文件描述符.先做个小测试: >>> import asyncio >>> ...

  4. struts2 jsp提交日期类型转换及国际化实现

    概述:下面通过jsp提交输入注册信息信息,同时完成过程文件国家化问题演示说明.[注册日期转换用注解方式实现] 工程截图: 注册页面jsp文件: <%@ page language="j ...

  5. 广播、多播和IGMP的一点记录

    广播和多播:仅应用于UDP 广播分为: 1.受限的广播(255.255.255.255) 2.指向网络的广播(eg:A类网络 netid.255.255.255)主机号为全1的地址 3.指向子网的广播 ...

  6. js 获取地理位置经纬度

    1. 加载百度API的核心js,ak表示获取百度地图的开发密钥,免费的需要申请下 <script type="text/javascript" src="http: ...

  7. 用于string对象中字符截取的几种函数总结——语法、参数意义及用途举例

    1. charAt():返回指定位置的字符. 语法:stringObject.charAt(index) 参数意义:index  必需,指字符在字符串中的下标.需要注意的是,字符串中第一个字符的下标是 ...

  8. Android之Handler使用方法总结

    方法一:(java习惯,在android平台开发时这样是不行的,由于它违背了单线程模型) 刚刚開始接触android线程编程的时候,习惯好像java一样,试图用以下的代码解决这个问题    new T ...

  9. -es6的部分语法

    es6的语法 一 . let 和 var 的区别 : 1 . let 和 val 的区别 :  ES6新增了let命令 , 用来声明变量,它的用法类似于 var (ES5), 但是所声明的变量,只在l ...

  10. Matlab图像处理(02)-图像基础

    数据类 Matlab中和IPT中支持的基本数据类型如下: 名称 描述 double 双精度浮点数,范围-10308~10308  8字节 uint8 无符号1字节整数,范围[0, 255] uint1 ...