POJ 1523 SPF tarjan求割点
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7110 | Accepted: 3242 |
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
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#include <typeinfo>
#include <map>
//#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************************************************
struct ss
{
int to,next;
}e[];
int dfn[],n,flag,low[],head[],cnt,t,iscut[];
void add(int u,int v)
{
e[t].to=v;
e[t].next=head[u];
head[u]=t++;
}
void init(){
cnt=;
t=;
flag=;
n=;
memset(head,,sizeof(head));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
}
void tarjan(int x)
{
dfn[x]=low[x]=++cnt;
for(int i=head[x];i;i=e[i].next)
{
if(!dfn[e[i].to])
{
tarjan(e[i].to);
low[x]=min(low[x],low[e[i].to]);
if(dfn[x]<=low[e[i].to])iscut[x]++;
}
else low[x]=min(low[x],dfn[e[i].to]);
}
}
int main()
{
int a,b;
int oo=;
while(scanf("%d",&a)!=EOF)
{
if(a==)break;
init();
scanf("%d",&b);
n=max(max(a,b),n);
add(a,b);
add(b,a);
while(scanf("%d",&a)&&a)
{
scanf("%d",&b);
n=max(max(a,b),n);
add(a,b);
add(b,a);
}
for(int i=;i<=n;i++)
{
iscut[i]=;
}
iscut[]=;///1为根必认定为割点
tarjan();
printf("Network #%d\n",oo++);
for(int i=;i<=n;i++)
{
if(iscut[i]>=){
flag=;
printf(" SPF node %d leaves %d subnets\n",i,iscut[i]);
}
}
if(!flag){
printf(" No SPF nodes\n");
}
printf("\n");
}
return ;
}
POJ 1523 SPF tarjan求割点的更多相关文章
- POJ 1523 SPF(求割点)
题目链接 题意 : 找出图中所有的割点,然后输出删掉他们之后还剩多少个连通分量. 思路 : v与u邻接,要么v是u的孩子,要么u是v的祖先,(u,v)构成一条回边. //poj1523 #includ ...
- poj 1523 SPF 无向图求割点
SPF Description Consider the two networks shown below. Assuming that data moves around these network ...
- poj 1523 SPF(双连通分量割点模板)
题目链接:http://poj.org/problem?id=1523 题意:给出无向图的若干条边,求割点以及各个删掉其中一个割点后将图分为几块. 题目分析:割点用tarjan算法求出来,对于每个割点 ...
- poj 1144 (Tarjan求割点数量)
题目链接:http://poj.org/problem?id=1144 描述 一个电话线公司(简称TLC)正在建立一个新的电话线缆网络.他们连接了若干个地点分别从1到N编号.没有两个地点有相同的号码. ...
- POJ 1523 SPF (去掉割点能形成联通块的个数)
思路:使用tarjan算法求出割点,在枚举去掉每一个割点所能形成的联通块的个数. 注意:后来我看了下别的代码,发现我的枚举割点的方式是比较蠢的方式,我们完全可以在tarjan过程中把答案求出来,引入一 ...
- [poj 1144]Network[Tarjan求割点]
题意: 求一个图的割点. 输入略特别: 先输入图中点的总数, 接下来每一行首先给出一个点u, 之后给出一系列与这个点相连的点(个数不定). 行数也不定, 用0作为终止. 这样的输入还是要保证以数字读入 ...
- poj 1523 SPF(tarjan求割点)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- POJ 1523 SPF (无向图割点)
<题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...
随机推荐
- B0BO TFS 安装指南(转载)
TFS2008安装过几次,每次都遇到点麻烦,结合网上的一些经验总结一下: Windows SharePoint Services 安装 Windows SharePoint Services你有两个选 ...
- ASP.NET MVC 站点设置.html 为起始页
1. 删除 controller="XX" 2. 确保你的工程根目录下的*.htm或*.html文件名在IIS默认文档中存在 搞定
- asp.net预定义的HttpModule
在asp.net中,已经预定义了很多HttpModule,甚至在服务器的网站配置文件中进行了注册,我们可以通过系统文件夹C:\Windows\Microsoft.NET\Framework\v4.0. ...
- Atlas安装及配置
==============linux下快捷键==================ctrl+insert 复制shift +insert 粘贴 输入文件名的前三个字母,按tab键自动补全文件名 在vi ...
- centos配置yum源
1.登录mirrors.163.com 2.点击centos后面的“centos使用帮助” 3.下载CentOS7-Base-163.repo 4.sudo mv /etc/yum.repos.d/C ...
- [OpenJudge 3064]坠落的蚂蚁
[OpenJudge 3064]坠落的蚂蚁 试题描述 一根长度为1米的木棒上有若干只蚂蚁在爬动.它们的速度为每秒一厘米或静止不动,方向只有两种,向左或者向右.如果两只蚂蚁碰头,则它们立即交换速度并继续 ...
- ubuntu硬盘安装卡在探测文件系统
在硬盘安装ubuntu的时候,会出现这样的问题:安装程序一直卡在正在探测文件系统就不动了.解决的方法很简单.在安装之前要在终端输入sudo空格umount空格 -l空格 /isodevice 不能少一 ...
- PHP表单验证
<!DOCTYPE html> <html> <head> <title>Test Code</title> </head> & ...
- MongoDB概述&语法
Nosql DB 这是一个非关系型数据库. 通常我们的数据库有三类: 关系型数据库(RDBMS),联机分析处理数据库(OLAP),和菲关系型数据库(NoSql). MongoDB属于第三种,而且是一 ...
- Linux下crontab命令的用法
cron来源于希腊单词chronos(意为“时间”),是linux系统下一个自动执行指定任务的程序.例如,你想在每晚睡觉期间创建某些文件或文件夹的备份,就可以用cron来自动执行. 服务的启动和停止 ...