SPF
Time limit:1000 ms |
|
Memory limit:10000 K |
Total submissions:2838 |
|
Accepted:1264 |
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 wowould prevent some of the still available nodes from
Communicating with each other. nodes 1 and 2 cocould still communicate with each other as cocould nodes 4 and 5, but communication between any other pairs of nodes wowould 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, wocould prevent at least one pair of available nodes from being able to communicate on what was previusly 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 in 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 shoshould 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 shocould 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 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 Node 3 leaves 2 subnets
Source
Greater New York 2000 question: http://poj.org/problem? Id = 1523 analysis: This is similar to poj 2117. when seeking a cut point, count which connected blocks belong to the cut point, and finally output the cut point, and number of connected parts of the cut point Code :
# Include <cstdio> # define min (a, B) (a <B? A: B) using namespace STD; const int Mm = 2222222; const int Mn = 11111; int T [mm], p [mm]; int H [Mn], num [Mn], dfn [Mn], low [Mn]; int I, J, K, E, RT, n, m, top, IDN, CAS = 0; bool GED; inline void addedge (int u, int v) {T [e] = V, p [e] = H [u], H [u] = e ++; T [e] = u, P [e] = H [v], H [v] = e ++;} void DFS (int u, int FA) {int I, v, CNT = 0; dfn [u] = low [u] = ++ IDN; for (I = H [u]; I> = 0; I = P [I]) if (! Dfn [V = T [I]) {DFS (v, U); ++ CNT; low [u] = min (low [u], low [v]); if (u = RT & CNT> 1) | (u! = RT & dfn [u] <= low [v]) ++ num [u], Ged = 1;} else if (V! = FA) low [u] = min (low [u], dfn [v]);} void Tarjan () {for (Top = IDN = RT = GED = 0; RT <= N; ++ RT) dfn [RT] = num [RT] = 0; For (RT = 1; RT <= N; ++ RT) if (! Dfn [RT]) DFS (RT, 0);} int main () {While (scanf ("% d", & I), I) {for (E = k = 0, n = I; k <Mn; ++ K) H [k] =-1; scanf ("% d", & J ); addedge (I, j); If (j> N) n = J; while (scanf ("% d", & I), I) {if (I> N) N = I; scanf ("% d", & J); If (j> N) n = J; addedge (I, j) ;} Tarjan (); printf ("Network # % d \ n", ++ CAS); If (GED) {for (I = 1; I <= N; ++ I) if (Num [I]) printf ("SPF node % d leaves % d subnets \ n", I, num [I] + 1 );} else printf ("No SPF nodes \ n"); printf ("\ n");} return 0 ;}