POJ1523 SPF[无向图割点]
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8139 | Accepted: 3723 |
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
Source
cut vertex裸题,只不过求的是能分成几个subnets,使成为割点的子节点数+1就行(还有父辈们一个),注意root不能加1
//
// main.cpp
// poj1523
//
// Created by Candy on 9/26/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=1e3+,INF=1e9+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x;
}
int n=,u,v,w,cas=;
struct edge{
int v,ne;
}e[N*N];
int h[N],cnt=;
inline void ins(int u,int v){
cnt++;
e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
cnt++;
e[cnt].v=u;e[cnt].ne=h[v];h[v]=cnt;
}
int pre[N],sn[N],dc=;
int dfs(int u,int fa){
int lowu=pre[u]=++dc,child=;
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;
if(!pre[v]){
child++;
int lowv=dfs(v,u);
lowu=min(lowu,lowv);
if(lowv>=pre[u]) sn[u]++;//,printf("v %d %d\n",u,v);
}else if(pre[v]<pre[u]&&v!=fa)
lowu=min(lowu,pre[v]);
}
if(fa==-&&child==) sn[u]=;
return lowu;
}
int main(int argc, const char * argv[]) {
while((u=read())){
int root=,flag=; n=;
memset(h,,sizeof(h)); cnt=;
memset(pre,,sizeof(pre));
memset(sn,,sizeof(sn));
v=read();
ins(u,v);
n=max(n,max(u,v));
while((u=read())){
v=read();
ins(u,v);
n=max(n,max(u,v)); root=u;
}
dfs(root,-);
if(sn[root]!=) sn[root]--;
printf("Network #%d\n",++cas);
for(int i=;i<=n;i++) if(sn[i]){
printf(" SPF node %d leaves %d subnets\n",i,sn[i]+);
flag=;
}
if(!flag) printf(" No SPF nodes\n");
printf("\n");
} return ;
}
POJ1523 SPF[无向图割点]的更多相关文章
- POJ1523 SPF(割点模板)
题目求一个无向图的所有割点,并输出删除这些割点后形成几个连通分量.用Tarjan算法: 一遍DFS,构造出一颗深度优先生成树,在原无向图中边分成了两种:树边(生成树上的边)和反祖边(非生成树上的边). ...
- POJ 1523 SPF (无向图割点)
<题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...
- tarkjan求无向图割点模板
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; ; ; struct node { ...
- POJ1144 Network 无向图割点
题目大意:求以无向图割点. 定义:在一个连通图中,如果把点v去掉,该连通图便分成了几个部分,则v是该连通图的割点. 求法:如果v是割点,如果u不是根节点,则u后接的边中存在割边(u,v),或者v-&g ...
- POJ1523:SPF(无向连通图求割点)
题目:http://poj.org/problem?id=1523 题目解析: 注意题目输入输入,防止PE,题目就是求割点,并问割点将这个连通图分成了几个子图,算是模版题吧. #include < ...
- poj 1523 SPF 无向图求割点
SPF Description Consider the two networks shown below. Assuming that data moves around these network ...
- SPF Tarjan算法求无向图割点(关节点)入门题
SPF 题目抽象,给出一个连通图的一些边,求关节点.以及每个关节点分出的连通分量的个数 邻接矩阵只要16ms,而邻接表却要32ms, 花费了大量的时间在加边上. // time 16ms 1 ...
- POJ 1523 SPF 求割点的好(板子)题!
题意: 给个无向图,问有多少个割点,对于每个割点求删除这个点之后会产生多少新的点双联通分量 题还是很果的 怎么求割点请参考tarjan无向图 关于能产生几个新的双联通分量,对于每个节点u来说,我们判断 ...
- POJ1523 SPF 单点故障
POJ1523 题意很简单,求删除割点后原先割点所在的无向连通图被分成了几个连通部分(原题说prevent at least one pair of available nodes from bein ...
随机推荐
- 安装配置php5.4 win2003
php php-5.4.38 1.下载 http://windows.php.net/downloads/releases/php-5.4.38-Win32-VC9-x86.zip 解压到 D:\we ...
- 【Leafletjs】5.L.Control 自定义一个Control
L.Control 所有leaflet控制的基础类.继承自IControl接口. 你可以这样添加控件: control.addTo(map); // the same as map.addContro ...
- '[<NSObject 0x8a4b500> setValue:forUndefinedKey:]
Bug如下: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUnd ...
- 实现微信浏览器内打开App Store链接(已被和谐,失效了)
微信浏览器是不支持打开App Store 页面的,不知道微信为什么这么做.比如你页面写 <a href=”http://itunes.apple.com/us/app/id399608199″& ...
- 操作系统开发系列—4.LDT
一直以来,我们把所有的段描述符都放在GDT中,而不管它属于内核还是用户程序,为了有效地在任务之间实施隔离,处理器建议每个任务都应当具有自己的描述符表,称为局部描述符表LDT,并且把专属于自己的那些段放 ...
- 限制EditText 输入的字节数
1.代码 name_tv = (EditText) findViewById( R.id.name_tv ); name_tv.addTextChangedListener(new TextWatch ...
- 使用mac 终端利用alias设置快捷命令
在终端中输入快捷命令可以提高工作效率,同时可以少记很多命令 如何做: 首先在~/目录下编辑 .bash_profile这个隐藏文件,如果你想直接双击此文件打开编辑的话请在终端输入 Mac 显示隐藏文件 ...
- MVC 生成图片,下载文件
/// <summary> /// 生成图片 /// </summary> /// <param name="collection"></ ...
- windows svn 上传后 自动部署 到web目录下
第一步 把web目录设置为工作目录 "D:\Program Files (x86)\VisualSVN Server\bin\svn.exe" upgrade "D:\y ...
- Mac下的快速回到桌面快捷方式
今天突然发现一个Mac下快速回到桌面的快捷方式. command+F3 快速回到桌面. 如果想增加动画效果,快捷键是: command+shift+F3 这个功能虽然小,但是确实非常实用啊!