SPF

Description

Consider the two networks shown below. Assuming that data moves around these networks only between directly connected nodes on a peer-to-peer basis, a failure of a single node, 3, in the network on the left would prevent some of the still available nodes from communicating with each other. Nodes 1 and 2 could still communicate with each other as could nodes 4 and 5, but communication between any other pairs of nodes would no longer be possible.

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

The input will contain the description of several networks. A network description will consist of pairs of integers, one pair per line, that identify connected nodes. Ordering of the pairs is irrelevant; 1 2 and 2 1 specify the same connection. All node numbers will range from 1 to 1000. A line containing a single zero ends the list of connected nodes. An empty network description flags the end of the input. Blank lines in the input file should be ignored.

Output

For each network in the input, you will output its number in the file, followed by a list of any SPF nodes that exist.

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

原题请戳这里

题意:

给定一个连通网络,网络的结点数<=1000,求出这个网络的所有割点编号,并求出若删去其中一个割点后,原网络会被分割为多少个互不相连的部分?

tips:

1.每组数据后输出空行

2.按顺序输出

3.图有可能不连通 Tarjan的时候不能把1当做root节点了。。。

#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int low[1005],dfn[1005],vis[1005],tot=1,T=1,n,m,q=0,W,cnt,root;
vector <int> v[1005];
void tarjan(int x){
dfn[x]=low[x]=tot++,vis[x]=1;
for(int i=0;i<v[x].size();i++)
if(!vis[v[x][i]]){
tarjan(v[x][i]),low[x]=min(low[x],low[v[x][i]]);
if(dfn[x]<=low[v[x][i]]) vis[x]++;
}
else low[x]=min(low[x],dfn[v[x][i]]);
if((x==root&&vis[x]>2)||(x!=root&&vis[x]>1)) vis[x]=2,v[1001].push_back(x);
else vis[x]=1;
}
void dfs(int x){
vis[x]=1;
for(int i=0;i<v[x].size();i++){
if(v[x][i]==W||x==W)continue;
if(!vis[v[x][i]])dfs(v[x][i]);
}
}
int main()
{
while(scanf("%d",&n)&&n)
start: scanf("%d",&m),q=max(q,max(n,m)),v[n].push_back(m),v[m].push_back(n);
printf("Network #%d\n",T);
for(int i=1;i<=q;i++)
if(!dfn[i])root=i,tarjan(i);
if(v[1001].size()==0)printf(" No SPF nodes\n");
sort(v[1001].begin(),v[1001].end());
for(int i=0;i<v[1001].size();i++){
memset(vis,0,sizeof(vis));cnt=0;
W=v[1001][i];
for(int j=1;j<=q;j++)
if(!vis[j])vis[j]=1,dfs(j),cnt++;
printf(" SPF node %d leaves %d subnets\n",W,cnt-1);
}
for(int i=1;i<=q;i++) v[i].clear();
v[1001].clear();
q=0;tot=1;T++;
memset(low,0,sizeof(low)),memset(dfn,0,sizeof(dfn)),memset(vis,0,sizeof(vis));
printf("\n");
scanf("%d",&n);
if(n)goto start;
}

POJ 1523 Tarjan求割点的更多相关文章

  1. POJ 1523 SPF 求割点的好(板子)题!

    题意: 给个无向图,问有多少个割点,对于每个割点求删除这个点之后会产生多少新的点双联通分量 题还是很果的 怎么求割点请参考tarjan无向图 关于能产生几个新的双联通分量,对于每个节点u来说,我们判断 ...

  2. poj 1523 SPF 求割点以及删除该割点后联通块的数量

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7136   Accepted: 3255 Description C ...

  3. poj 1523 SPF(tarjan求割点)

    本文出自   http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...

  4. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  5. UESTC 900 方老师炸弹 --Tarjan求割点及删点后连通分量数

    Tarjan算法. 1.若u为根,且度大于1,则为割点 2.若u不为根,如果low[v]>=dfn[u],则u为割点(出现重边时可能导致等号,要判重边) 3.若low[v]>dfn[u], ...

  6. poj_1144Network(tarjan求割点)

    poj_1144Network(tarjan求割点) 标签: tarjan 割点割边模板 题目链接 Network Time Limit: 1000MS Memory Limit: 10000K To ...

  7. 洛谷P3388 【模板】割点(割顶)(tarjan求割点)

    题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...

  8. POJ 1523 SPF (无向图割点)

    <题目链接> 题目大意: 给你一个连通的无向图,问你其中割点的编号,并且输出删除该割点后,原图会被分成几个连通分量. 解题分析: Tarjan求割点模板题. #include <cs ...

  9. [POJ1144][BZOJ2730]tarjan求割点

    求割点 一种显然的n^2做法: 枚举每个点,去掉该点连出的边,然后判断整个图是否联通 用tarjan求割点: 分情况讨论 如果是root的话,其为割点当且仅当下方有两棵及以上的子树 其他情况 设当前节 ...

随机推荐

  1. [测试工具]----iperf

    iperf https://sourceforge.net/projects/iperf/ http://downloads.es.net/pub/iperf/ https://github.com/ ...

  2. jquery制作动态添加表单行与删除表单行

    <script type="text/javascript" src="js/jquery1.7.js"></script> <s ...

  3. 7-13 航空公司VIP客户查询 (25 分)

    题意: 思路: 读完题目之后的第一思路就是用map将客户的id(string类型)与里程road(int类型)形成映射,然后直接用id查找添加里程或输出里程.但是400ms的限制妥妥的超时了.然后意识 ...

  4. Spring 注解注入的几种方式(转)

    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...

  5. JS布尔值(Boolean)转换规则

    原文作者: louis 原文链接: http://louiszhai.github.io/2015/12/11/js.boolean/ 语法 众所周知, JavaScript有五个基本的值类型:num ...

  6. 一个电商项目的Web服务化改造6:单元测试4步走,构造数据、执行操作、断言、回滚

      最近一直在做一个电商项目,需要把原有单系统架构的项目,改造成基于服务的架构,SOA.     有点挑战,做完了,会有很大进步. 单元测试,在很早之前的文章已经介绍过.     可以在这里看到相关的 ...

  7. 联赛前集训日记Day3

    考试 竟然出了道莫比乌斯函数的应用?? 简直没法玩 刷题 莫比乌斯函数摆在面前,咋能很快改完啊 生活 GGGGGGGGGGG 自己浪过头了,开回家一周 这车翻得猝不及防,然而自己作的,自己受,只是给别 ...

  8. 【ACM】hdu_zs3_1007_Rails_201308100802

    Rails Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)Total Submissi ...

  9. asp.net--mvc--异步编程

    Using Asynchronous Methods in ASP.NET MVC 4 asp.net mvc中的异步只能增加系统的性能,原来需要500个线程的,现在需要50个就够了,对一些常规的程序 ...

  10. MOS文章翻译

    http://blog.csdn.net/column/details/msdnchina.html?&page=1 http://blog.csdn.net/staricqxyz/artic ...