POJ1523(割点所确定的连用分量数目,tarjan算法原理理解)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7406 | Accepted: 3363 |
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.
![](http://poj.org/images/1523_1.jpg)
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
题意:问将某个点删除可产生多少个连通分量。
思路:考察对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算法原理理解)的更多相关文章
- 寻找图的强连通分量:tarjan算法简单理解
1.简介tarjan是一种使用深度优先遍历(DFS)来寻找有向图强连通分量的一种算法. 2.知识准备栈.有向图.强连通分量.DFS. 3.快速理解tarjan算法的运行机制提到DFS,能想到的是通过栈 ...
- 有向图强连通分量的Tarjan算法
有向图强连通分量的Tarjan算法 [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G ...
- 【转】有向图强连通分量的Tarjan算法
原文地址:https://www.byvoid.com/blog/scc-tarjan/ [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly con ...
- 算法笔记_144:有向图强连通分量的Tarjan算法(Java)
目录 1 问题描述 2 解决方案 1 问题描述 引用自百度百科: 如果两个顶点可以相互通达,则称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G是一个强连 ...
- 【转载】有向图强连通分量的Tarjan算法
转载地址:https://www.byvoid.com/blog/scc-tarjan [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly conn ...
- 有向图强连通分量的Tarjan算法(转)
[有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly connected).如果有向图G的每两个顶点都强连通,称G是一个强连通图.非强连通图有向图的极 ...
- 强连通分量的Tarjan算法
资料参考 Tarjan算法寻找有向图的强连通分量 基于强联通的tarjan算法详解 有向图强连通分量的Tarjan算法 处理SCC(强连通分量问题)的Tarjan算法 强连通分量的三种算法分析 Tar ...
- 『图论』有向图强连通分量的Tarjan算法
在图论中,一个有向图被成为是强连通的(strongly connected)当且仅当每一对不相同结点u和v间既存在从u到v的路径也存在从v到u的路径.有向图的极大强连通子图(这里指点数极大)被称为强连 ...
- 有向图强连通分量的Tarjan算法及模板
[有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强联通(strongly connected),如果有向图G的每两个顶点都强联通,称有向图G是一个强联通图.非强联通图有向 ...
随机推荐
- C#里类的get和set方法编写和调用
using System; class Date { int day; int month; int year; public int Day{ get { return day; } set { d ...
- JavaScript -- JavaScript高级程序设计
/* 基本类型 Undefined, Null, Boolean, Number, String. 复杂类型 Object 它是所有对象的基础类型. 引用类型 Object 创建:new Ojbect ...
- 32.10 使用模板更改控件的UI
32.10 使用模板更改控件的UI 样式是改变WPF控件基本外形的非常好(且非常简单)的方式,它通过为窗口部件的特性设置建立一组默认的值,从而改变WPF控件的基本外形.但是,即使样式允许我们改变各种 ...
- C++复习:位运算
与 a&b : 1010&1100=1000 或 a|b : 1010|1100=1110 异或 a^b : 101 ...
- Django项目高频使用文件
数据库配置: MySQL数据库 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'HOST': 'localhost' ...
- centos 7 PostgreSQL一些简单问题以及解决办法
问题:org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are corre ...
- POJ3984 迷宫问题【水BFS】
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011775691/article/details/28050277 #include <cs ...
- SpringBoot学习笔记(10):使用MongoDB来访问数据
SpringBoot学习笔记(10):使用MongoDB来访问数据 快速开始 本指南将引导您完成使用Spring Data MongoDB构建应用程序的过程,该应用程序将数据存储在MongoDB(基于 ...
- 微信小程序开发:学习笔记[3]——WXSS样式
微信小程序开发:学习笔记[3]——WXSS样式 快速开始 介绍 WXSS(WeiXin Style Sheets)是一套用于小程序的样式语言,用于描述WXML的组件样式,也就是视觉上的效果. WXSS ...
- 在Spring中基于JDBC进行数据访问时如何控制超时
超时分类 超时根据作用域可做如下层级划分: Transaction Timeout > Statement Timeout > JDBC Driver Socket Timeout Tra ...