"Bzoj 2730" [HNOI2012] mine construction

Source: Internet
Author: User

Description Coal mine site can be seen as a tunnel connected to the coal-mining point of the non-map. 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 line I is started with case I: (note the capitalization,there is 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 for Group I Input data requires at least a few rescue exits, and the second positive integer indicates the total number of setup scenarios for which the input data for group I is different from 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 Input9
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 OutputCase 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). Look for the cut point on the map do not build a safe point in the cut point the answer is C (n,2) Delete cut point run connectivity if there are two or more cut points in a unicom block there is no need to build, collapsed a can also run to other places there is a cut point to build one, do not build a cut point
1#include <cstdio>2#include <cstring>3#include <iostream>4 using namespacestd;5 Const intn=510;6 structee{intTo,next;} e[n*N];7 intHead[n],dfn[n],low[n],size[n],sum[n];8 BOOLCut[n],vis[n],vis1[n];9 intCnt,n,sz,t,m,timer;Ten Long LongNum,ans; One voidInsintUintv) { Ae[++cnt].to=v,e[cnt].next=head[u],head[u]=CNT; -e[++cnt].to=u,e[cnt].next=head[v],head[v]=CNT; - } the intTarjan (intUintFA) { -     intChild=0, Lowu; -lowu=dfn[u]=low[u]=++timer; -      for(intI=head[u];i;i=E[i].next) { +         intv=e[i].to; -         if(!Dfn[v]) { +child++; A             intlowv=Tarjan (v,u); atlowu=min (LOWU,LOWV); -             if(Lowv>=dfn[u]) cut[u]=1;  -         } -         Else if(dfn[v]<dfn[u]&&v!=FA) -lowu=min (lowu,dfn[v]); -     } in     if(fa<0&&child==1) cut[u]=0; -low[u]=Lowu; to     returnLowu; + } -   the voidDfsintXintSZ) { *vis[x]=1; size[sz]++; $      for(intI=head[x];i;i=E[i].next) {Panax Notoginseng         intv=e[i].to; -         if(!vis[v]&&!Cut[v]) { the DFS (V,SZ); +}Else{ A             if(Cut[v]&&!vis1[v]) sum[sz]++,vis1[v]=1; the         } +     } - } $   $ intMain () { -      while(1){ -scanf"%d",&m); the         if(m==0) Break; -cnt=n=sz=timer=num=0; ans=1;WuyiMemset (Head,0,sizeof(head)); theMemset (E,0,sizeof(e)); -memset (Cut,0,sizeof(cut)); Wumemset (Vis,0,sizeof(Vis)); -memset (Low,0,sizeof(Low)); Aboutmemset (DFN,0,sizeof(DFN)); $memset (SUM,0,sizeof(sum)); -memset (Size,0,sizeof(size)); -t++;p rintf ("Case %d:", T); -         intu,v; A          for(intI=1; i<=m;i++){ +scanf"%d%d",&u,&v); theN=max (n,u), n=Max (n,v); - ins (u,v); $         } theTarjan (1,-1); the          for(intI=1; i<=n;i++)if(!cut[i]&&!Vis[i]) { thememset (Vis1,0,sizeof(VIS1)); theDFS (i,++sz); -         } in         if(sz==1) ans= (n1) *n/2, num=2; the         Else{ the              for(intI=1; i<=sz;i++){ About                 if(sum[i]==1) ans*=size[i],num++; the             } the         } theprintf"%lld%lld\n", Num,ans); +     } -}

"Bzoj 2730" [HNOI2012] mine construction

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.