POJ 1523 SPF (non-graph cut top)

Source: Internet
Author: User

Spf

Description

Consider the 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, and 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 all other as could Nodes 4 and 5, but communication between all other pairs of Nodes would no longer be possible.

Node 3 is therefore a, Failure (SPF) for this network. Strictly, an SPF would be defined as any node that, if unavailable, would prevent at least one pair of available nodes from Being able to communicate in what is previously a fully connected network. Note the network on the right have no such node; There is no SPF in the network. At least machines must fail before there is any pairs of available nodes which cannot communicate.

Input

The input would contain the description of several networks. A Network description would 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 would 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 is ignored.

Output

For each network in the input, you'll output its number in the file, and followed by a list of all SPF nodes that exist.

The first network in the file should is 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 ful Ly connected subnets that remain where 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 25 43 13 23 43 501 22 33 44 55 101 22 33 44 66 32 55 100

Sample Output

Network #1  SPF node 3 leaves 2 subnetsnetwork #2  No SPF nodesnetwork #3  SPF node 2 leaves 2 subnets  SPF No De 3 leaves 2 subnets

1#include <cstdio>2#include <vector>3#include <cstring>4 using namespacestd;5 6vector<int>g[1005];7 BOOLFlag;8 intlow[1005],dfs_clock,pre[1005];9 BOOLiscut[1005];Ten BOOLvis[1005]; One  A voidInit () - { -memset (Iscut,0,sizeof(Iscut)); thememset (PRE,0,sizeof(pre)); -memset (Vis,0,sizeof(Vis)); -      for(intI=0;i<1005; i++) g[i].clear (); -dfs_clock=0; +flag=0; - } +  A intFindcut (intUintFA) at { -     intlowu=pre[u]=++Dfs_clock; -     intChild=0; -      for(intI=0; I<g[u].size (); i++) -     { -         intv=G[u][i]; in         if(!Pre[v]) -         { tochild++; +             intlowv=findcut (v,u); -lowu=min (LOWU,LOWV); the             if(lowv>=Pre[u]) *iscut[u]=true; $         }Panax Notoginseng         Else if(pre[v]<pre[u]&&v!=FA) -lowu=min (lowu,pre[v]); the     } +     if(fa<0&&child==1) iscut[u]=0; Alow[u]=Lowu; the     returnLowu; + } -  $ voidDfsintu) $ { -vis[u]=1; -      for(intI=0; I<g[u].size (); i++) the     if(!Vis[g[u][i]]) -     {Wuyivis[g[u][i]]=1; the DFS (G[u][i]); -     } Wu } -  About voidoutput () $ { -      for(intI=1;i<1005; i++) -     { -         if(Iscut[i]) A         { +flag=1; thememset (Vis,0,sizeof(Vis)); -vis[i]=1; $             intson=0; the              for(intj=0; J<g[i].size (); j + +) the             { the                 if(!Vis[g[i][j]]) the                 { - DFS (G[i][j]); inson++; the                 } the             } Aboutprintf"SPF node%d leaves%d subnets\n", I,son); the         } the     } the     if(!flag) +printf"No SPF nodes\n"); -printf"\ n"); the }Bayi  the intMain () the { -     //freopen ("In.txt", "R", stdin); -     intu,v,t; the     BOOLkey=0; thet=0; the      while(SCANF ("%d",&u)) the     { -         if(u==0&&key) the          Break; the         Else if(u==0&&!key) the         {94printf"Network #%d\n",++t); theFindcut (1,-1); the output (); the init ();98key=1; About             Continue; -         }101         if(u!=0) key=0;Elsekey=1;102scanf"%d",&v);103 G[u].push_back (v);104 g[v].push_back (u); the     }106     return 0;107}

POJ 1523 SPF (non-graph cut top)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.