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. python学习之常用模块

  2. backtrace函数

    1.函数原型 #include <execinfo.h> int backtrace(void **buffer, int size); 该函数获取当前线程的调用堆栈,获取的信息将会被存放 ...

  3. react ant-design自定义图标

    ant-design给我们提供的图标不够怎么办呢?答案是我们可以自定义图标. 自定义图标也挺简单的,现在图标推荐用svg格式,那么我们就需要制作svg图片. 下面让我们看看如果制作svg图片吧. 1. ...

  4. FIFO的使用场景

    (1) 数据的缓冲.如模型图所示,如果数据的写入速率高,但间隔大,且会有突发;读出速率小,但相对均匀.则通过设置相应深度的FIFO,可以起到数据暂存的功能,且能够使后续处理流程平滑,避免前级突发时,后 ...

  5. python基础之try异常处理、socket套接字基础part1

    异常处理 错误 程序里的错误一般分为两种: 1.语法错误,这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正 2.逻辑错误,人为造成的错误,如数据类型错误.调用方法错误等,这些解 ...

  6. 从浏览器或者Webview 中唤醒APP

    本文来自网易云社区 作者:刘新奇 移动互联时代,很多互联网服务都会同时具备网站以及移动客户端,很多人认为APP的能帮助建立更稳固的用户关系,于是经常会接到各种从浏览器.webview中唤醒APP的需求 ...

  7. iOS开发中常见的一些异常

    iOS开发中常见的异常包括以下几种NSInvalidArgumentExceptionNSRangeExceptionNSGenericExceptionNSInternallnconsistency ...

  8. ubuntu开启crontab日志

    今天发现Ubuntu的/var/log下没有cron日志,用下面的命令即可开启: -default.conf cron.*              /var/log/cron.log #将cron前 ...

  9. web端常见兼容性问题整理

    一.html和css 各浏览器的默认内外边距不一致问题 最明显的是ul标签内外边距问题,ul标签在IE-7中,有个默认的外边距,但是在IE8以上及其他浏览器中有个默认的内边距. 解决办法:*{marg ...

  10. .netcore centos环境搭建实战

    步骤 1. 安装VMware Workstation 下载地址:https://my.vmware.com/cn/web/vmware/info/slug/desktop_end_user_compu ...