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

题意: 求割点 并输出 (当删除割点时) 将原图分为几个连通图;

题解: tarjan 模板

low[u] 是从u或u的子孙出发通过回边能够到达的最低深度优先数

dfn[u] 时间戳

u是关节点的 条件

1. 若u为根节点 u至少有两个子女

2. 若u不是根节点  他又一个子女w low[w]>=dfn[u]

 #include<iostream>
#include<cstring>
#include<cstdio>
#define ll __int64
#define mod 1
#define PI acos(-1.0)
using namespace std;
int Edge[][];
int visited[];
int nodes;
int tmpdfn;
int dfn[];
int low[];
int son;
int subnets[];
void dfs(int u)
{
for(int v=;v<=nodes;v++)
{
if(Edge[u][v])
{
if(!visited[v])
{
visited[v]=;
tmpdfn++ ;
dfn[v]=low[v]=tmpdfn;
dfs(v);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u])
{
if(u!=)
subnets[u]++;
if(u==)
son++;
} }
else
low[u]=min(low[u],dfn[v]);
}
}
}
void init()
{
low[]=dfn[]=;
tmpdfn=;
son=;
memset(visited,,sizeof(visited));
visited[]=;
memset(subnets,,sizeof(subnets));
}
int main()
{
int i;
int u,v;
int find;
int number=;
while()
{
scanf("%d",&u);
if(u==)
break;
memset(Edge,,sizeof(Edge));
nodes=;
scanf("%d",&v);
if(u>nodes)
nodes=u;
if(v>nodes)
nodes=v;
Edge[u][v]=;
Edge[v][u]=;
while()
{
scanf("%d",&u);
if(u==)
break;
scanf("%d",&v);
if(u>nodes)
nodes=u;
if(v>nodes)
nodes=v;
Edge[u][v]=;
Edge[v][u]=;
}
if(number>)
printf("\n");
printf("Network #%d\n",number);
number++;
init();
dfs();
if(son>)
subnets[]=son-;
find=;
for(i=;i<=nodes;i++)
{
if(subnets[i])
{
find=;
printf(" SPF node %d leaves %d subnets\n",i,subnets[i]+);
}
}
if(!find)
printf(" No SPF nodes\n"); }
return ;
}
/*割点 图论书模板*/

poj 1523 割点 tarjan的更多相关文章

  1. POJ 1523 SPF tarjan求割点

                                                                   SPF Time Limit: 1000MS   Memory Limit ...

  2. POJ 1523 (割点+连通分量)

    题目链接:http://poj.org/problem?id=1523 题目大意:连通图,找图中割点,并计算切除该割点后,图中的连通分量个数. 解题思路: POJ的数据很弱. Tarjan法求割点. ...

  3. SPF POJ - 1523 割点+并查集

    题意: 问你这个图中哪个点是割点,如果把这个点去掉会有几个子网 代码: 1 //给你几个点,用着几个点形成了一个图.输入边形成的图,问你这个图中有多少个割点.每一个割点去掉后会形成几个强连通分量 2 ...

  4. Electricity POJ - 2117 + SPF POJ - 1523 去除割点后求强连通分量个数问题

    Electricity POJ - 2117 题目描述 Blackouts and Dark Nights (also known as ACM++) is a company that provid ...

  5. poj 3417 Network(tarjan lca)

    poj 3417 Network(tarjan lca) 先给出一棵无根树,然后下面再给出m条边,把这m条边连上,然后每次你能毁掉两条边,规定一条是树边,一条是新边,问有多少种方案能使树断裂. 我们设 ...

  6. 洛谷3388 【模板】割点 tarjan算法

    题目描述 给出一个n个点,m条边的无向图,求图的割点. 关于割点 在无向连通图中,如果将其中一个点以及所有连接该点的边去掉,图就不再连通,那么这个点就叫做割点(cut vertex / articul ...

  7. zoj 1119 / poj 1523 SPF (典型例题 求割点 Tarjan 算法)

    poj : http://poj.org/problem?id=1523 如果无向图中一个点 u 为割点 则u 或者是具有两个及以上子女的深度优先生成树的根,或者虽然不是一个根,但是它有一个子女 w, ...

  8. poj 1523 SPF(tarjan求割点)

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

  9. POJ 1523 SPF 割点与桥的推断算法-Tarjan

    题目链接: POJ1523 题意: 问一个连通的网络中有多少个关节点,这些关节点分别能把网络分成几部分 题解: Tarjan 算法模板题 顺序遍历整个图,能够得到一棵生成树: 树边:可理解为在DFS过 ...

随机推荐

  1. C++代码理解 (强制指针转换)

    #include<iostream> using namespace std; class A { public: A() { a=; b=; c=; f=; } private: int ...

  2. ISE中FPGA的实现流程

    一.ISE实现的步骤         在综合之后,我们开始启动FPGA在ISE中的实现过程,整个过程包括以下几个步骤:                 1.Translate              ...

  3. IdFTP中FEAT命令的问题

    IdFTP控件很方便开发FTP客户端,用于传输文件.一次笔者的一个在阿里云的服务器突发故障,显示无法登陆FTP,而使用其他客户端(如FlashFxp)经过该项目设置,又可正常使用. 查询后说是FEAT ...

  4. Android开发——告诉你Adapter应该写在Activity里面还是外面

    0. 前言 本文转载自AItsuki的博客. 首先说明一下为什么要写这么一篇博客:最近看了一些其他人的项目,发现很多项目的做法是建立一个专门存放Adapter类的Package包,也有的项目干脆直接都 ...

  5. Python3: 对两个字符串进行匹配

    Python里一共有三种字符串匹配方式,用于判断一个字符串是否包含另一个字符串.比如判断字符串“HelloWorld”中是否包含“World”: def stringCompare(str1, str ...

  6. luogu4172 [WC2006]水管局长

    就是用 lct 维护最小生成树 ref #include <algorithm> #include <iostream> #include <cstdio> #in ...

  7. PS作业

  8. jmeter上传视频图片附件

    http上传附件一般用的Content-Type: multipart/form-data;文中是先通过fiddler抓取手机端的请求,然后通过jmeter模拟该请求,如果有接口文档,则可以跳过抓包这 ...

  9. 【APUE】Chapter1 UNIX System Overview

    这章内容就是“provides a whirlwind tour of the UNIX System from a programmer's perspective”. 其实在看这章内容的时候,已经 ...

  10. python下的自动化测试--selenium 验证码输入问题

    之前一直在研究scrapy下数据抓取,在研究ajax数据抓取时碰巧研究了一下selenium,确实很实用,不过只做scrapy下的数据抓取,不怎么合适,一是性能的损耗,一直需要开一个浏览器,二是对于爬 ...