[HNOI2012] Mine construction
Description
The coal mine site can be regarded as a non-direction diagram which is composed of a tunnel connecting coal mining points. For the sake of safety, I hope that all the coal miners in the construction site will have a way to escape to the rescue exit. So the miners decided to set up rescue exits at certain coal-mining points, so that no matter which coal-mining point collapsed, other coal-mining workers had a road leading to the rescue exit. Please write a program to calculate the total number of settings that need to be set at least several rescue exits, as well as different minimum rescue exits.
Input
The input file has several sets of data, the first line of each group of data is a positive integer N (n≤500), representing the number of tunnels at the site, and the next N rows are two integers separated by a space of S and T, which means that the digging S and the coal mining point T are directly connected by the tunnel. The input data ends with 0.
Output
How many sets of data are in the input file, and how many lines are in the output file output.txt. Each row corresponds to the result of a set of input data. Where the line I: Start (note case, I have a space between, I and: there is no space between,: Then there is a space), followed by a space separated by two positive integers, the first positive integer indicates that for group I input data need to set at least a few rescue exits, a second positive integer for the first Group input data The total number of setup scenarios for the minimum rescue exit. The input data guarantees that the answer is less than 2^64. The output format references the following input and output samples.
Sample Input
9
1 3
4 1
3 5
1 2
2 6
1 5
6 3
1 6
3 2
6
1 2
1 3
2 4
2 5
3 6
3 7
0
Sample Output
Case 1:2 4
Case 2:4 1
HINT
Case 1 of the four groups of solutions are (2,4), (3,4), (4,5), (4,6);
A set of solutions for Case 2 is (4,5,6,7).
Source
Day1
Analysis:
It is obvious that the point of collapse is to influence the cut point.
A cut point is deleted, will be divided into multiple connected blocks, each connected block to arrange an exit, the number of schemes is obviously the product of each connected block points.
But there will be a lot of cutting points, that is, each cut point to meet the above conditions.
Consider deleting all the cut points and then finding the connected blocks, and multiplying all the points connected with only one cut-point connected block is the scheme number.
If the entire graph has no cut point, or all points are either cut points or connected to multiple cut points, the minimum number of exits is 2 and the scheme is C (n,2).
Code:
Programbuild;type Point=^node; Node=Recordx:longint; next:point; End;varA:Array[0.. -] ofPoint ; Dfn,low,r:Array[0.. -] ofLongint; Mk,g:Array[0.. -] ofBoolean; N,i,m,s,num,j,x,y,tot:longint; S1,s2,ans:int64;procedureAdd (x,y:longint);varP:point;beginnew (P); p^.x:=y; P^.NEXT:=A[X]; a[x]:=p;End;functionmin (x,y:longint): Longint;begin ifX<y ThenMin:=xElsemin:=y;End;procedureTarjan (x,fa:longint);vary,k:longint; p:point;beginInc (s); Low[x]:=s; dfn[x]:=s; New (P); P:=A[X]; k:=0; whileP<>Nil Do beginy:=p^.x; ifdfn[y]=0 Then beginInc (k); Tarjan (Y,X); LOW[X]:=min (low[x],low[y]); ifLOW[Y]>=DFN[X] Thenmk[x]:=true; End Else if(Dfn[y]<dfn[x]) and(Y<>FA) Thenlow[x]:=min (low[x],dfn[y]); P:=P^.next; End; if(k=1) and(fa=-1) Thenmk[x]:=false;End;procedureDFS (x:longint);vary:longint; p:point;beginNew (P);p:=A[X]; g[x]:=true; Inc (S2); whileP<>Nil Do beginy:=p^.x; ifG[y]=false Then ifMk[y]=true Then beginG[y]:=true; Inc (S1); R[s1]:=y;End Elsedfs (y); P:=P^.next; End;End;beginNum:=0; m:=1; whileM<>0 Do beginReadln (m); ifm=0 ThenBreak ; Inc. (NUM); N:=0; fori:=1 to - Doa[i]:=Nil; fori:=1 toM Do beginreadln (x, y); ifX>n Thenn:=x; ifY>n Thenn:=y; Add (x, y); add (y,x); End; fori:=1 toN Do begindfn[i]:=0; low[i]:=0; Mk[i]:=false;g[i]:=false;End; S:=0; tot:=0; ans:=1; Tarjan (1,-1); fori:=1 toN Do if( notMk[i]) and( notG[i]) Then beginS1:=0; s2:=0; DFS (i); ifs1=1 Then beginInc (TOT); ANS:=ANS*S2;End; forj:=1 toS1 Dog[r[j]]:=false; End; iftot=0 Then begintot:=2; ans:=n* (n1)Div 2;End; Writeln (' Case'Num': 'Tot' ', ans); End;End.
View Code
Bzoj 2730:[hnoi2012] Mine construction (cut point + connected block)