Topic:
Test instructions
Gave a unicom without a map, now ask to remove a point, will make the diagram into a few unicom block?
The output is divided by the number of small, if equal, the output label from small to large. Output of M.
Analysis:
The number of connected blocks after the BCC cut point, Tarjan algorithm.
The number of Unicom blocks is accumulated when a low[y]>=dfn[x] is found, and the last one can be added.
The code is as follows:
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 #defineMAXN 100108 9 intn,m;Ten intFIRST[MAXN],LOW[MAXN],DFN[MAXN],FA[MAXN],SON[MAXN]; One intCUT[MAXN]; A intCNT; - - structnode the { - intX,y,next; - }; -Node t[maxn*Ten],ANS[MAXN]; + intLen; - + intMymin (intXintY) {returnX<y?x:y;} A at voidInsintXinty) - { -t[++len].x=x;t[len].y=y; -t[len].next=first[x];first[x]=Len; - } - in BOOLCMP (node X,node y) {return(x.x==y.x)? (X.Y<Y.Y):(x.x>y.x);} - to voidFfind (intXintf) + { -dfn[x]=low[x]=++CNT; thefa[x]=F; * for(intI=first[x];i;i=t[i].next)if(t[i].y!=f) $ {Panax Notoginseng inty=t[i].y; - if(dfn[y]==0) the { + Ffind (y,x); Ason[x]++; thelow[x]=mymin (Low[x],low[y]); + if(Low[y]>=dfn[x]) cut[x]++; - } $ Elselow[x]=mymin (Low[x],dfn[y]); $ } - } - the intMain () - {Wuyi while(1) the { -scanf"%d%d",&n,&m); Wu if(n==0&&m==0) Break; -len=0; cnt=0; Aboutmemset (First,0,sizeof(first)); $ while(1) - { - intb; -scanf"%d%d",&a,&b); A if(a==-1&&b==-1) Break; +a++;b++; the ins (A, B); ins (b,a); - } $memset (DFN,0,sizeof(DFN)); thememset (Cut,0,sizeof(cut)); theMemset (son,0,sizeof(son)); theFfind (1,0); ans[1].y=0; the if(son[1]>1) ans[1].x=son[1]; - Elseans[1].x=1; in for(intI=2; i<=n;i++) the { theans[i].y=i-1; Aboutans[i].x=cut[i]+1; the } theSort (ans+1, ans+1+n,cmp); the for(intI=1; i<=m;i++) printf ("%d%d\n", ans[i].y,ans[i].x); +printf"\ n"); - } the return 0;Bayi}
[UVA10765]
2016-03-17 13:43:40
"UVA10765" Doves and Bombs (BCC cut-off points after the number of unicom blocks)