"Bzoj" "2730" "HNOI2012" mine construction

Source: Internet
Author: User

Tarjan seek bcc/cut point

However, it seems that I began to copy the petition board where the wrong copy? Or what is wrong with itself ... (may not apply to this question?) Because this problem requires the size of each BCC to be calculated.

Worship the YDC of the writing = =

In fact, two times Dfs is not more than the trouble of Lrj where to go ... The feeling is more clear and understandable, not easy to make a bug

Everyone is noip before they ask for cutting points ... Only I am more stupid ...

The core is $low [Son]\geq DFN[FA] \rightarrow FA is cut point $

Well, if there's only one bcc, then only two exits are required, and if a BCC is connected to two (and above?). ) Cut point (here the two cut points directly connected can be regarded as a bcc?) So it doesn't have to be built inside, or it needs to be built. Of course the number of programs directly multiply just fine = = (Size[x], depending on the representation, may require-1 minus the cut point)

1 /**************************************************************2 problem:27303 User:tunix4 language:c++5 result:accepted6 time:0 Ms7 memory:1308 KB8 ****************************************************************/9  Ten //Bzoj 2730 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #defineCC (A, B) memset (A,b,sizeof (a)) + using namespacestd; AtypedefLong LongLL; atInlineintGetint () { -     intR=1, v=0;CharCh=GetChar (); -      for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') r=-1; -      for(; isdigit (ch); Ch=getchar ()) v=v*Ten-'0'+ch; -     returnr*v; - } in Const intn=510; - /*******************template********************/ to   + structedge{intX,y,next;} e[n<<1],st[n<<1]; - intn,m,head[n],cnt; the voidAddintXinty) { *E[++cnt]= (Edge) {x,y,head[x]}; head[x]=CNT; $E[++cnt]= (Edge) {Y,x,head[y]}; head[y]=CNT;Panax Notoginseng } - intDfn[n],low[n],dfs_clock,bccno[n],have[n],size[n],bcc,top; the BOOLIscut[n]; +   A voidTarjan (intXintFA) { thelow[x]=dfn[x]=++Dfs_clock; +     intChild=0; -      for(intI=head[x];i;i=E[i].next) { $         inty=e[i].y; $         if(!Dfn[y]) { -child++; - Tarjan (y,x); thelow[x]=min (low[y],low[x]); -             if(Low[y]>=dfn[x]) iscut[x]=1;Wuyi}Elselow[x]=min (low[x],dfn[y]); the     } -     if(fa<0&& child==1) iscut[x]=0; Wu } -   About BOOLVis[n]; $ voidDfsintx) { -vis[x]=1; size[bcc]++; -      for(intI=head[x];i;i=e[i].next) -         if(!Vis[e[i].y]) { A             if(!Iscut[e[i].y]) DFS (E[I].Y); +             Else if(bccno[e[i].y]!=bcc) thebccno[e[i].y]=bcc,have[bcc]++; -         } $ } the voidClear () { theCC (Head,0); CC (Bccno,0); theCC (DFN,0); CC (Low,0); theCC (Have,0); CC (Size,0); -CC (Iscut,0); CC (Vis,0); inn=cnt=dfs_clock=bcc=top=0; the } the intMain () { About #ifndef Online_judge theFreopen ("2730.in","R", stdin); theFreopen ("2730.out","W", stdout); the #endif  +     intcs=0; -      while(SCANF ("%d", &m)!=eof &&m) { theprintf"Case %d:",++CS);Bayi Clear (); theF (I,1, M) { the             intX=getint (), y=getint (); -N=max (X,n); n=Max (y,n); - Add (x, y); the         } theF (I,1, N)if(!dfn[i]) Tarjan (i,-1); theLL ans1=0, ans2=1; theF (I,1, N) -             if(!vis[i] &&!Iscut[i]) { the++Bcc,dfs (i); the                 if(have[bcc]==1) ans1++,ans2*=SIZE[BCC]; the             }94         if(bcc==1) ans1=2, ans2= (LL) n (n1)/2; theprintf"%lld%lld\n", ans1,ans2); the     } the     return 0;98}
View Code 2730: [HNOI2012] Mine build time limit:10 Sec Memory limit:128 MB
submit:974 solved:458
[Submit] [Status] [Discuss] 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 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 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
The solutions for the four groups of Hintcase 1 were (2,4), (3,4), (4,5), (4,6);
A set of solutions for Case 2 is (4,5,6,7). Source

Day1

[Submit] [Status] [Discuss]

"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.