Mining Your Own businesstime limit:1000msmemory limit:32768kbthis problem would be judged onHDU. Original id:3844
64-bit integer IO format: %i64d Java class name: Main John Digger is the owner of a large Illudium Phosdex mine. The mine is made up of a series of tunnels that meet at various large junctions. Unlike some owners, Digger actually cares about the welfare of his workers and have a concern about the layout of the mine. Specifically, he worries that there could a junction which, in case of collapse, would cut off workers in one section of the Mine from other workers (Illudium Phosdex, as-you-know, is highly unstable). To counter this, he wants to install special escape shafts from the junctions to the surface. The He could install one escape shaft at the junction, but Digger doesn ' t care on his workers that much. Instead, he wants to install the minimum number of escape shafts so that if any of the junctions collapses, all the worker s who survive the junction collapse would have a path to the surface.
Write a program to calculate the minimum number of escape shafts and the total number of ways in which this minimum number of escape shafts can be installed.InputThe input consists of several test cases. The first line of all case contains a positive integer n (n <= 5x10^4) indicating the number of mine tunnels. Following this is N lines each containing a distinct integers s and t, where s and T are junction numbers. Junctions is numbered consecutively starting at 1. Each pair of junctions are joined by at the most a single tunnel. Each of the set of mine tunnels forms one connected unit (that is, the can get from any one junction to any other).
The last test case was followed by a line containing a single zero.OutputFor each test case, display it case number followed by the minimum number of escape shafts needed for the system of mine Tunnels and the total number of ways these escape shafts can be installed. Assume that the result fits in a signed 64-bit integer.
Follow the format of the sample output.Sample Input
91 34 13 51 22 61 56 31 63 261 21 32 42 53 63 70
Sample Output
Case 1:2 4Case 2:4 1
Source2011WorldFinal Problem Solving: Point two connected components, of course, I am not directly to the point of the two connected components, I am seeking cutting points. First find the cut point, and then start from the non-cutting point DFS, in the DFS process, can not go through the cut point. Select a location to install when there is only one cut point in the two connected components of a point and the optional location of the installation does not include a cut point. When the entire figure does not have a cut point, need two position, because if one, just put the ladder position hanging, all hung up. So just pick two locations. This topic needs to expand the stack .... The topic of WF is full of pits.
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 #pragmaComment (linker, "/stack:102400000,102400000")6 using namespacestd;7typedefLong LongLL;8 Const intMAXN =50010;9 structArc {Ten intTo,next; OneArcintx =0,inty =-1) { Ato =x; -Next =y; - } the} e[1000010]; - intHEAD[MAXN],DFN[MAXN],LOW[MAXN],IDX,TOT,CN; - BOOLCUT[MAXN]; - voidAddintUintv) { +E[tot] =arc (V,head[u]); -Head[u] = tot++; +E[tot] =arc (U,head[v]); AHEAD[V] = tot++; at } - voidTarjan (intUintFA) { -Dfn[u] = Low[u] = + +idx; - intson =0; - for(inti = Head[u]; ~i; i =E[i].next) { - if(e[i].to = = FA)Continue; in if(!Dfn[e[i].to]) { - Tarjan (e[i].to,u); toson++; +Low[u] =min (low[u],low[e[i].to]); - if(FA! =-1&& low[e[i].to] >= Dfn[u] | | FA = =-1&& son >1) { theCut[u] =true; *cn++; $ }Panax Notoginseng}ElseLow[u] =min (low[u],dfn[e[i].to]); - } the } + BOOLVIS[MAXN]; A intCnt,n,m,cao; the BOOLFK[MAXN]; + voidDfsintUintFA) { -Vis[u] =true; $cnt++; $ for(inti = Head[u]; ~i; i =E[i].next) { - if(e[i].to = = FA)Continue; - if(Cut[e[i].to]) { the if(!Fk[e[i].to]) { -cao++;WuyiFk[e[i].to] =true; the } - Continue; Wu } - if(Vis[e[i].to])Continue; About DFS (E[I].TO,FA); $ } - } - intMain () { - intU,v,cs =1; A while(SCANF ("%d",&m), (m) { +memset (head,-1,sizeofhead); the for(inti = tot = n = idx = CN =0; I < m; ++i) { -scanf"%d%d",&u,&v); $ Add (u,v); then =Max (N,max (u,v)); the } thememset (DFN,0,sizeofDFN); thememset (Cut,false,sizeofcut); - for(inti =1; I <= N; ++i) in if(!dfn[i]) Tarjan (i,-1); theLL ret =1; the if(!CN) printf ("Case %d:%d%i64d\n", cs++,2, (LL) n (n1)/2); About Else { thememset (Vis,false,sizeofvis); the intRI =0; the for(inti =1; I <= N; ++i) { + if(Cut[i] | | vis[i])Continue; -CNT = Cao =0; theMemset (FK,false,sizeofFK);BayiDFS (i,-1); the if(Cao <2&& cnt) {ri++; RET *=CNT;} the } -printf"Case %d:%d%i64d\n", cs++, Ri,ret); - } the } the return 0; the}
View Code
HDU 3844 Mining Your Own Business