Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8254   Accepted: 3772

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. 1 2
  2. 5 4
  3. 3 1
  4. 3 2
  5. 3 4
  6. 3 5
  7. 0
  8.  
  9. 1 2
  10. 2 3
  11. 3 4
  12. 4 5
  13. 5 1
  14. 0
  15.  
  16. 1 2
  17. 2 3
  18. 3 4
  19. 4 6
  20. 6 3
  21. 2 5
  22. 5 1
  23. 0
  24.  
  25. 0

Sample Output

  1. Network #1
  2. SPF node 3 leaves 2 subnets
  3.  
  4. Network #2
  5. No SPF nodes
  6.  
  7. Network #3
  8. SPF node 2 leaves 2 subnets
  9. SPF node 3 leaves 2 subnets

Source

点双连通分量模板题

  1. /*by SilverN*/
  2. #include<algorithm>
  3. #include<iostream>
  4. #include<cstring>
  5. #include<cstdio>
  6. #include<cmath>
  7. #include<vector>
  8. using namespace std;
  9. const int mxn=;
  10. struct edge{
  11. int v,nxt;
  12. }e[mxn<<];
  13. int hd[mxn],mct=;
  14. void add_edge(int u,int v){
  15. e[++mct].v=v;e[mct].nxt=hd[u];hd[u]=mct;
  16. return;
  17. }
  18. int n;
  19. int low[mxn],dfn[mxn],dtime=;
  20. int num[mxn];
  21. int st[mxn],top=;
  22. bool cut[mxn];
  23. void DFS(int u,int fa){
  24. low[u]=dfn[u]=++dtime;
  25. st[++top]=u;
  26. int i,j;
  27. for(i=hd[u];i;i=e[i].nxt){
  28. int v=e[i].v;
  29. if(v==fa)continue;
  30. if(!dfn[v]){
  31. DFS(v,u);
  32. if(low[v]>=dfn[u]){
  33. cut[u]=;
  34. int s=;
  35. do{
  36. s=st[top--];
  37. ++num[s];
  38. }while(u!=s);
  39. top++;
  40. }
  41. // num[u]++;
  42. low[u]=min(low[u],low[v]);
  43. }
  44. else low[u]=min(dfn[v],low[u]);
  45. }
  46. return;
  47. }
  48. bool have[mxn];
  49. int main(){
  50. int cas=;
  51. while(){
  52. memset(hd,,sizeof hd);
  53. memset(cut,,sizeof cut);
  54. memset(low,,sizeof low);
  55. memset(dfn,,sizeof dfn);
  56. memset(have,,sizeof have);
  57. memset(num,,sizeof num);
  58. mct=dtime=top=;
  59. int i,j,u,v;
  60. bool flag=;
  61. while(scanf("%d",&u) && u){
  62. scanf("%d",&v);
  63. have[u]=have[v]=;
  64. add_edge(u,v);
  65. add_edge(v,u);
  66. flag=;
  67. }
  68. if(!flag)break;
  69. for(i=;i<=;i++)
  70. if(have[i] && !dfn[i])DFS(i,);
  71. printf("Network #%d\n",++cas);
  72. flag=;
  73. for(i=;i<=;i++){
  74. if(num[i]>=){
  75. flag=;
  76. printf(" SPF node %d leaves %d subnets\n",i,num[i]);
  77. }
  78. }
  79. if(!flag)printf(" No SPF nodes\n");
  80. printf("\n");
  81. }
  82. return ;
  83. }

POJ1523 SPF的更多相关文章

  1. POJ1523 SPF[无向图割点]

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8139   Accepted: 3723 Description C ...

  2. POJ1523 SPF 单点故障

    POJ1523 题意很简单,求删除割点后原先割点所在的无向连通图被分成了几个连通部分(原题说prevent at least one pair of available nodes from bein ...

  3. POJ1523 SPF(割点模板)

    题目求一个无向图的所有割点,并输出删除这些割点后形成几个连通分量.用Tarjan算法: 一遍DFS,构造出一颗深度优先生成树,在原无向图中边分成了两种:树边(生成树上的边)和反祖边(非生成树上的边). ...

  4. POJ1523:SPF(无向连通图求割点)

    题目:http://poj.org/problem?id=1523 题目解析: 注意题目输入输入,防止PE,题目就是求割点,并问割点将这个连通图分成了几个子图,算是模版题吧. #include < ...

  5. poj图论解题报告索引

    最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...

  6. Tarjan求割点和桥

    by szTom 前置知识 邻接表存储及遍历图 tarjan求强连通分量 割点 割点的定义 在一个无向图中,如果有一个顶点集合,删除这个顶点集合以及这个集合中所有顶点相关联的边以后,图的连通分量增多, ...

  7. POJ1523:SPF——题解

    http://poj.org/problem?id=1523 这题明显就是求割点然后求割完之后的强连通分量的个数. 割点都会求,怎么求割完的分量个数呢? 我们可以通过万能的并查集啊!(具体做法看代码吧 ...

  8. POJ 1523 SPF(求割点)

    题目链接 题意 : 找出图中所有的割点,然后输出删掉他们之后还剩多少个连通分量. 思路 : v与u邻接,要么v是u的孩子,要么u是v的祖先,(u,v)构成一条回边. //poj1523 #includ ...

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

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

随机推荐

  1. oracle用sqlplus创建新用户,不是plsql developer

    1.sqlplus /nolog 2.conn /as sysdba 3.alter user system identified by "123456"; 4.alter use ...

  2. final-----finalize----finally---区别

    一.性质不同 (1)final为关键字: (2)finalize()为方法: (3)finally为为区块标志,用于try语句中: 二.作用 (1)final为用于标识常量的关键字,final标识的关 ...

  3. [转]redis.conf的配置解析

    # redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位, # 通常的格式就是 1k 5gb 4m 等酱紫: # # 1k => 1000 bytes # 1kb ...

  4. Minimum Window Substring

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  5. Jdev Run Page 没有反应

    从旧电脑把原有的Jdeveloper完整的拷贝至新电脑,且已完整配置JDEV_USER_HOME,JAVA_HOME等环境变量, Run Page报以下错误. [Starting OC4J using ...

  6. System.Web.HttpRequestValidationException——从客户端检测到危险的Request值

    这是比较常见的问题了,如果Web表单中有输入类似于Html标签之类的文本,在通过Request.QueryString或者Request.Form传递这些值的时候,就会触发这样的异常,出于脚本注入等安 ...

  7. 软件开发之路、Step 1 需求分析

    百度百科 需求分析 所谓"需求分析",是指对要解决的问题进行详细的分析,弄清楚问题的要求,包括需要输入什么数据,要得到什么结果,最后应输出什么.可以说,在软件工程当中的“需求分析” ...

  8. 用python简单处理图片(2):图像通道\几何变换\裁剪

    一.图像通道 1.彩色图像转灰度图 from PIL import Image import matplotlib.pyplot as plt img=Image.open('d:/ex.jpg') ...

  9. gdb学习

    gdb学习 [参考资料] http://www.cnblogs.com/jiu0821/p/4483804.html 程序的运行状态有"运行"."暂停".&qu ...

  10. 零散知识记录-一个MQ问题

    [背景]我有一项零散工作:维护大部门的一台测试公用MQ服务器.当大部分MQ被建立起来,编写了维护手册,大家都按照规程来后,就基本上没有再动过它了.周五有同学跟我反映登录不进去了,周日花了1个小时来解决 ...