poj 1523 割点 tarjan
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
题意: 求割点 并输出 (当删除割点时) 将原图分为几个连通图;
题解: tarjan 模板
low[u] 是从u或u的子孙出发通过回边能够到达的最低深度优先数
dfn[u] 时间戳
u是关节点的 条件
1. 若u为根节点 u至少有两个子女
2. 若u不是根节点 他又一个子女w low[w]>=dfn[u]
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll __int64
#define mod 1
#define PI acos(-1.0)
using namespace std;
int Edge[][];
int visited[];
int nodes;
int tmpdfn;
int dfn[];
int low[];
int son;
int subnets[];
void dfs(int u)
{
for(int v=;v<=nodes;v++)
{
if(Edge[u][v])
{
if(!visited[v])
{
visited[v]=;
tmpdfn++ ;
dfn[v]=low[v]=tmpdfn;
dfs(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
if(u!=)
subnets[u]++;
if(u==)
son++;
} }
else
low[u]=min(low[u],dfn[v]);
}
}
}
void init()
{
low[]=dfn[]=;
tmpdfn=;
son=;
memset(visited,,sizeof(visited));
visited[]=;
memset(subnets,,sizeof(subnets));
}
int main()
{
int i;
int u,v;
int find;
int number=;
while()
{
scanf("%d",&u);
if(u==)
break;
memset(Edge,,sizeof(Edge));
nodes=;
scanf("%d",&v);
if(u>nodes)
nodes=u;
if(v>nodes)
nodes=v;
Edge[u][v]=;
Edge[v][u]=;
while()
{
scanf("%d",&u);
if(u==)
break;
scanf("%d",&v);
if(u>nodes)
nodes=u;
if(v>nodes)
nodes=v;
Edge[u][v]=;
Edge[v][u]=;
}
if(number>)
printf("\n");
printf("Network #%d\n",number);
number++;
init();
dfs();
if(son>)
subnets[]=son-;
find=;
for(i=;i<=nodes;i++)
{
if(subnets[i])
{
find=;
printf(" SPF node %d leaves %d subnets\n",i,subnets[i]+);
}
}
if(!find)
printf(" No SPF nodes\n"); }
return ;
}
/*割点 图论书模板*/
poj 1523 割点 tarjan的更多相关文章
- POJ 1523 SPF tarjan求割点
SPF Time Limit: 1000MS Memory Limit ...
- POJ 1523 (割点+连通分量)
题目链接:http://poj.org/problem?id=1523 题目大意:连通图,找图中割点,并计算切除该割点后,图中的连通分量个数. 解题思路: POJ的数据很弱. Tarjan法求割点. ...
- SPF POJ - 1523 割点+并查集
题意: 问你这个图中哪个点是割点,如果把这个点去掉会有几个子网 代码: 1 //给你几个点,用着几个点形成了一个图.输入边形成的图,问你这个图中有多少个割点.每一个割点去掉后会形成几个强连通分量 2 ...
- Electricity POJ - 2117 + SPF POJ - 1523 去除割点后求强连通分量个数问题
Electricity POJ - 2117 题目描述 Blackouts and Dark Nights (also known as ACM++) is a company that provid ...
- poj 3417 Network(tarjan lca)
poj 3417 Network(tarjan lca) 先给出一棵无根树,然后下面再给出m条边,把这m条边连上,然后每次你能毁掉两条边,规定一条是树边,一条是新边,问有多少种方案能使树断裂. 我们设 ...
- 洛谷3388 【模板】割点 tarjan算法
题目描述 给出一个n个点,m条边的无向图,求图的割点. 关于割点 在无向连通图中,如果将其中一个点以及所有连接该点的边去掉,图就不再连通,那么这个点就叫做割点(cut vertex / articul ...
- zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)
poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...
- poj 1523 SPF(tarjan求割点)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- POJ 1523 SPF 割点与桥的推断算法-Tarjan
题目链接: POJ1523 题意: 问一个连通的网络中有多少个关节点,这些关节点分别能把网络分成几部分 题解: Tarjan 算法模板题 顺序遍历整个图,能够得到一棵生成树: 树边:可理解为在DFS过 ...
随机推荐
- python的爬虫代理设置
现在网站大部分都是反爬虫技术,最简单就是加代理,写了一个代理小程序. # -*- coding: utf-8 -*- #__author__ = "雨轩恋i" #__date__ ...
- nodejs环境变量配置
步骤 创建文件夹:安装包 配置环境变量: export NODE_HOME=/root/安装包/node-v7.6.0-linux-x64 export PATH=$NODE_HOME/bin:$PA ...
- gp的纯属意外的意外
一不小心,把方法都传过去了,一脸蒙蔽说的就是我,啊哈哈哈啊哈
- 【jQuery】 实用 js
[jQuery] 实用 js 1. int 处理 parseInt(") // int 转换 isNaN(page) // 判断是否是int类型 2. string 处理 // C# str ...
- innodb_index_stats
mysql> select * from mysql.innodb_index_stats WHERE database_name='test' and table_name='recordsI ...
- 如何修改Github上提交的错误用户地址和姓名
Changing author info https://help.github.com/articles/changing-author-info/ To change the name an ...
- Qt Charts实践
Qt Charts的横空出世标志着QWT,QCustomPlot .....时代的终结,让我们开始使用QtCharts吧 在Qt 5.7.0中已经集成了Qt Charts模块,需要在安装Qt的时候把C ...
- python 基础篇 10 函数进阶
本节主要内容:1. 函数参数--动态传参2. 名称空间, 局部名称空间, 全局名称空间, 作⽤域, 加载顺序.3. 函数的嵌套4. gloabal, nonlocal关键字 ⼀. 函数参数--动态传参 ...
- hibernate和mybatis的之CRUD封装差别
hibernate和mybatis的之CRUD封装差别 以下讲的是基于MVC三层架构. 由于设计架构的差别,hibernate在实际编程中可以把基础的CRUD封装,比如BaseDao类.其它类只要去继 ...
- python基础之列表解析
python列表解析:是一个让人欣喜的术语,你可以在一行使用一个for循环将所有的值放在一个列表之中.python列表解析属于python的迭代中的一种,相比python for循环速度会快很多. e ...