Bzoj2730 [HNOI2012] Mine construction

Source: Internet
Author: User

Time Limit:10 Sec Memory limit:128 MB
submit:1667 solved:787 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).

Source

Day1

Point two connected components. Only when the cut point in the picture collapses, will someone be trapped. Tarjan find all the cut points, and then the statistics only connected to a cut point of the Unicom block (if the Unicom block attached to two cut points, one can not be from another to the other), the answer is tired by the conditions of the Unicom block points. ↑ input Data read in is the number of sides, silly as a point, read into the wrong, but also always check the problem of the algorithm ... ↑wa to fly after the anger to see the key, code to change and Tunix the basic same, only to find read into ... (Hope Day)
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8 #defineLL unsigned long Long9 using namespacestd;Ten Const intmxn=100010; One intRead () { A     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} the     returnx*F; - } - structedge{ -     intv,nxt; + }E[MXN]; - inthd[mxn],mct=0; + voidAdd_edge (intUintv) { Ae[++mct].v=v;e[mct].nxt=hd[u];hd[u]=MCT; at     return; - } - intDfn[mxn],low[mxn],dtime; - intbct=0; - BOOLCUT[MXN]; - voidDFS (intUintFA) { indfn[u]=low[u]=++Dtime; -     intChild=0; to      for(intI=hd[u];i;i=e[i].nxt) { +         intv=e[i].v; -         if(V==FA)Continue; the         if(!Dfn[v]) { *child++; $ DFS (v,u);Panax Notoginsenglow[u]=min (low[u],low[v]); -             if(Dfn[u]<=low[v]) cut[u]=1; the         } +         Elselow[u]=min (low[u],dfn[v]); A     } the     if(!fa && child==1) cut[u]=0; +     return; - } $ BOOLVIS[MXN];intNUM[MXN],BELONE[MXN],HAVE[MXN]; $ voidSolveintu) { -vis[u]=1; num[bct]++; -      for(intI=hd[u];i;i=e[i].nxt) { the         intv=e[i].v; -         if(!Vis[v]) {Wuyi             if(!cut[v]) solve (v); the             Else if(belone[v]!=BCT) { -belone[v]=BCT; Wuhave[bct]++; -             } About         } $     } -     return; - } - intn,m; ALL ans=0; + voidinit () { thememset (DFN,0,sizeofDFN); -memset (Low,0,sizeofLow ); $memset (HD,0,sizeofHD); thememset (Cut,0,sizeofcut); thememset (NUM,0,sizeofnum); thememset (Vis,0,sizeofvis); theMemset (Have,0,sizeofhave ); -mct=0; ans=1; bct=0;d time=0; n=0; in } the intMain () { the     inti,j,u,v; About     intcas=0; the      while(SCANF ("%d", &m) &&m) { the init (); the          for(i=1; i<=m;i++){ +U=read (); v=read (); -n=Max (N,max (u,v)); the Add_edge (u,v);Bayi Add_edge (v,u); the         } the          for(i=1; i<=n;i++)if(!dfn[i]) DFS (I,0); -         intres=0; -          for(i=1; i<=n;i++){ the             if(!vis[i] &&!Cut[i]) { thebct++; the solve (i); the                 if(have[bct]==1) res++,ans*=NUM[BCT]; -             } the         } the         if(bct==1) res=2, ans= (LL) n (n1)/2; theprintf"Case %d:",++CAs);94printf"%d", res); theprintf"%llu\n", ans); the     } the     return 0;98}

Bzoj2730 [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.