POJ1523 SPF
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 8254 | Accepted: 3772 |
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
点双连通分量模板题
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
struct edge{
int v,nxt;
}e[mxn<<];
int hd[mxn],mct=;
void add_edge(int u,int v){
e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;
return;
}
int n;
int low[mxn],dfn[mxn],dtime=;
int num[mxn];
int st[mxn],top=;
bool cut[mxn];
void DFS(int u,int fa){
low[u]=dfn[u]=++dtime;
st[++top]=u;
int i,j;
for(i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(v==fa)continue;
if(!dfn[v]){
DFS(v,u);
if(low[v]>=dfn[u]){
cut[u]=;
int s=;
do{
s=st[top--];
++num[s];
}while(u!=s);
top++;
}
// num[u]++;
low[u]=min(low[u],low[v]);
}
else low[u]=min(dfn[v],low[u]);
}
return;
}
bool have[mxn];
int main(){
int cas=;
while(){
memset(hd,,sizeof hd);
memset(cut,,sizeof cut);
memset(low,,sizeof low);
memset(dfn,,sizeof dfn);
memset(have,,sizeof have);
memset(num,,sizeof num);
mct=dtime=top=;
int i,j,u,v;
bool flag=;
while(scanf("%d",&u) && u){
scanf("%d",&v);
have[u]=have[v]=;
add_edge(u,v);
add_edge(v,u);
flag=;
}
if(!flag)break;
for(i=;i<=;i++)
if(have[i] && !dfn[i])DFS(i,);
printf("Network #%d\n",++cas);
flag=;
for(i=;i<=;i++){
if(num[i]>=){
flag=;
printf(" SPF node %d leaves %d subnets\n",i,num[i]);
}
}
if(!flag)printf(" No SPF nodes\n");
printf("\n");
}
return ;
}
POJ1523 SPF的更多相关文章
- POJ1523 SPF[无向图割点]
SPF Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8139 Accepted: 3723 Description C ...
- POJ1523 SPF 单点故障
POJ1523 题意很简单,求删除割点后原先割点所在的无向连通图被分成了几个连通部分(原题说prevent at least one pair of available nodes from bein ...
- POJ1523 SPF(割点模板)
题目求一个无向图的所有割点,并输出删除这些割点后形成几个连通分量.用Tarjan算法: 一遍DFS,构造出一颗深度优先生成树,在原无向图中边分成了两种:树边(生成树上的边)和反祖边(非生成树上的边). ...
- POJ1523:SPF(无向连通图求割点)
题目:http://poj.org/problem?id=1523 题目解析: 注意题目输入输入,防止PE,题目就是求割点,并问割点将这个连通图分成了几个子图,算是模版题吧. #include < ...
- poj图论解题报告索引
最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...
- Tarjan求割点和桥
by szTom 前置知识 邻接表存储及遍历图 tarjan求强连通分量 割点 割点的定义 在一个无向图中,如果有一个顶点集合,删除这个顶点集合以及这个集合中所有顶点相关联的边以后,图的连通分量增多, ...
- POJ1523:SPF——题解
http://poj.org/problem?id=1523 这题明显就是求割点然后求割完之后的强连通分量的个数. 割点都会求,怎么求割完的分量个数呢? 我们可以通过万能的并查集啊!(具体做法看代码吧 ...
- POJ 1523 SPF(求割点)
题目链接 题意 : 找出图中所有的割点,然后输出删掉他们之后还剩多少个连通分量. 思路 : v与u邻接,要么v是u的孩子,要么u是v的祖先,(u,v)构成一条回边. //poj1523 #includ ...
- POJ 1523 SPF 割点与桥的推断算法-Tarjan
题目链接: POJ1523 题意: 问一个连通的网络中有多少个关节点,这些关节点分别能把网络分成几部分 题解: Tarjan 算法模板题 顺序遍历整个图,能够得到一棵生成树: 树边:可理解为在DFS过 ...
随机推荐
- C++ 基础笔记(一)
解释型和编译型 解释型: 边解释边执行,翻译成机器代码后就执行. 编译型: 整篇代码编译成机器码后,保存在可执行文件中,然后启动该程序文件,运行获得结果. Hello World #include & ...
- css3爆炸效果更换图片轮播图
思路:给一个div设置一个背景图片1.jpg,然后在这个div上面用两个for循环动态的创建一个列数为C行数为R数量的span,并给这些span设置宽高.定位并设置背景图片0.jpg,然后设置每个sp ...
- sql 索引 填充因子(转)
和索引重建最相关的是填充因子.当创建一个新索引,或重建一个存在的索引时,你可以指定一个填充因子,它是在索引创建时索引里的数据页被填充的数量.填充因子设置为100意味着每个索引页100%填满,50%意味 ...
- 基于Nodejs生态圈的TypeScript+React开发入门教程
基于Nodejs生态圈的TypeScript+React开发入门教程 概述 本教程旨在为基于Nodejs npm生态圈的前端程序开发提供入门讲解. Nodejs是什么 Nodejs是一个高性能Ja ...
- [tools]神器notepad++
1,现象 notepad++编辑sh文件,放入linux后执行会有问题 2,解决: 2.1dos2unix转换文件 2,2 修改notepad++默认字符集 2,快捷键: ctrl+k 单行.多行注释 ...
- C语言 数组类型与数组指针类型
//数组类型与数组指针类型 #include<stdio.h> #include<stdlib.h> #include<string.h> void main(){ ...
- no.4 抽奖测试
#-*-coding=gbk-*- import sys import random a=[] try: for x in range(1,20+1,1): #打印20人数编号 a.append(x) ...
- [转]World Wind Java开发之四——搭建本地WMS服务器
在提供地理信息系统客户端时,NASA还为用户提供了开源的WMS Server 服务器应用:World Wind WMS Server.利用这个应用,我们可以架设自己的WMS服务并使用自己的数据(也支持 ...
- 优化Webstorm
Webstorm这个编辑器还是很强大的,而且版本更新得快,支持最新的typescript,就是性能越来越低. 本文总结了一些优化Webstorm的有效方法,希望对大家有所帮助! 测试环境 Mac OS ...
- Android 中R文件丢失问题解决方案
Project → clean 项目上右键→android Tools→ fix project 检查xml文件中有无命名错误,特别是@+id写成@id的[特别是这条,注意看控制台打印的xml错误]