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. Source Insight的使用

    1. source insight查看函数的上一级调用的位置(函数) --> 鼠标放在函数上,右键 选择 Jump To caller,就可以看到有哪些函数调用它了:

  2. Scrapy框架的基本使用

    安装 pip install scrapy 基础使用 1. 创建一个工程:scrapy startproject 2. 在工程目录下创建一个爬虫文件 cd 工程 scrapy genspider 爬虫 ...

  3. (杭电 1097)A hard puzzle

    A hard puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. Qt——菜单栏、工具栏、状态栏

    1.菜单栏 菜单栏的意义是将可点击触发最终事件的集中在一起,所以菜单栏中是QAction 添加菜单栏是QMainWindow的行为 QMenubar *menubar = this->addMe ...

  5. linux网络服务实验

    1.设置window IP地址为192.168.3.XX,掩码24位. 2.设置Linux IP地址为192.168.3.YY,掩码24位.window与Linux互相ping通. 3.在linux中 ...

  6. git使用ssh密钥(转)

    git使用https协议,每次pull, push都要输入密码,相当的烦.使用git协议,然后使用ssh密钥.这样可以省去每次都输密码. 大概需要三个步骤:一.本地生成密钥对:二.设置github上的 ...

  7. thrift 调取 python php go 客户端代码

    golang package main import ( "fmt" "git.apache.org/thrift.git/lib/go/thrift" &qu ...

  8. Linux 服务器 监控命令

    1 top top类似于windows下面的资源管理器.不仅能够从服务器整体上展示服务器的大致情况,还可以看到具体进程 耗费资源的情况. 展示内存.cpu.交换分区等信息 如上图: 第一行主要描述系统 ...

  9. 1,理解java中的IO

    IO中的几种形式 基于字节:InputStream.OutputStream 基于字符:Writer.Reader 基于磁盘:File 基于网络Socket   最终都是字节操作,字符到字节要编码转换 ...

  10. MySQL数据库性能优化专题

    摘录: 书:<MySQL性能调优与架构设计> 一个系列: (按顺序排一下) MySQL 数据库性能优化之缓存参数优化 http://isky000.com/database/mysql-p ...