poj 1523 SPF 无向图求割点
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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int dfn[];
int low[];
int head[];
int ans[];
int visit[];
int index,root,son,node,jiedge;
struct is
{
int u,v;
int next;
}edge[];
void add(int x,int y)
{
jiedge++;
edge[jiedge].u=x;
edge[jiedge].v=y;
edge[jiedge].next=head[x];
head[x]=jiedge;
jiedge++;
edge[jiedge].u=y;
edge[jiedge].v=x;
edge[jiedge].next=head[y];
head[y]=jiedge;
}
void dfs(int u)
{
for(int i=head[u];i;i=edge[i].next)
{
int v=edge[i].v;
if(visit[v]==)
{
visit[v]=;++index;
dfn[v]=low[v]=index;
dfs(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
if(u==root)
son++;
else
ans[u]++;
}
}
else
low[u]=min(low[u],dfn[v]);
}
}
void trajan()
{
memset(visit,,sizeof(visit));
memset(ans,,sizeof(ans));
index=;
root=;
son=;
low[]=dfn[]=;
visit[]=;
dfs();
}
int main()
{
int u,v;
int flag=;
while(scanf("%d",&u)!=EOF)
{
memset(head,,sizeof(head));
jiedge=;
node=;
if(u==)
break;
scanf("%d",&v);
node=max(node,u);
node=max(node,v);
add(u,v);
while()
{
scanf("%d",&u);
if(u==)
break;
scanf("%d",&v);
add(u,v);
node=max(node,u);
node=max(node,v);
}
trajan();
int kk=;
if(flag!=)
printf("\n");
printf("Network #%d\n",++flag);
if(son>)
{
kk=;
printf(" SPF node %d leaves %d subnets\n",,son);
}
for(int i=;i<=node;i++)
{
if(ans[i])
{
kk=;
printf(" SPF node %d leaves %d subnets\n",i,ans[i]+);
}
}
if(kk)
printf(" No SPF nodes\n");
}
return ;
}
poj 1523 SPF 无向图求割点的更多相关文章
- POJ 1523 SPF tarjan求割点
SPF Time Limit: 1000MS Memory Limit ...
- POJ 1523 SPF(求割点)
题目链接 题意 : 找出图中所有的割点,然后输出删掉他们之后还剩多少个连通分量. 思路 : v与u邻接,要么v是u的孩子,要么u是v的祖先,(u,v)构成一条回边. //poj1523 #includ ...
- POJ 1523 SPF (无向图割点)
<题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- poj 1144 Network 无向图求割点
Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...
- POJ 1523 SPF (去掉割点能形成联通块的个数)
思路:使用tarjan算法求出割点,在枚举去掉每一个割点所能形成的联通块的个数. 注意:后来我看了下别的代码,发现我的枚举割点的方式是比较蠢的方式,我们完全可以在tarjan过程中把答案求出来,引入一 ...
- UVA 315 Network (模板题)(无向图求割点)
<题目链接> 题目大意: 给出一个无向图,求出其中的割点数量. 解题分析: 无向图求割点模板题. 一个顶点u是割点,当且仅当满足 (1) u为树根,且u有多于一个子树. (2) u不为树根 ...
- poj 1523"SPF"(无向图求割点)
传送门 题意: 有一张联通网络,求出所有的割点: 对于割点 u ,求将 u 删去后,此图有多少个联通子网络: 对于含有割点的,按升序输出: 题解: DFS求割点入门题,不会的戳这里
- zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)
poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...
随机推荐
- 让Logstash每次都从头读文件及常见问题
input { file { path => ["/data/test.log"] start_position => "beginning" si ...
- Saving Princess claire_(hdu 4308 bfs模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...
- 微信小程序- wx.request请求不到数据
小程序官方文档手册 https://mp.weixin.qq.com/debug/wxadoc/dev/ 小程序开发问答社区 http://www.henkuai.com/forum.php wx.r ...
- 多项式函数插值:全域多项式插值(一)单项式基插值、拉格朗日插值、牛顿插值 [MATLAB]
全域多项式插值指的是在整个插值区域内形成一个多项式函数作为插值函数.关于多项式插值的基本知识,见“计算基本理论”. 在单项式基插值和牛顿插值形成的表达式中,求该表达式在某一点处的值使用的Horner嵌 ...
- [转载]C#深拷贝的方法
首先了解下深拷贝和浅拷贝的定义: 浅拷贝(影子克隆):只复制对象的基本类型,对象类型,仍属于原来的引用. 深拷贝(深度克隆):不紧复制对象的基本类,同时也复制原对象中的对象.就是说完全是新对 ...
- linux字符处理命令 sort(部分转载)
[root@LocalWeb01 ~]# sort /etc/passwd |less (升序 ) [root@LocalWeb01 ~]# sort -r /etc/passwd |less ( ...
- JaveScript-简介
1.JaveScript:脚本语言.(弱类型语言)可以写在head,也可以写在head里,同样可以写在html外面<script src=""></script& ...
- mac远程连接windows
第一步:在Mac上安装Remote Desktop Connection 进入Microsoft Remote Desktop Connection下载安装包. 下载完成之后,双击安装包进行安装. 第 ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON HistoToThresh1
zw版[转发·台湾nvp系列Delphi例程]HALCON HistoToThresh1 procedure TForm1.Button1Click(Sender: TObject);var imag ...
- MyBatis学习笔记(七)——Mybatis缓存
转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4270403.html 一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓 ...