HDU 3844 Mining Your Own Business (cut point, warp, open stack, classic)

Source: Internet
Author: User

Test instructions: Give a connected graph, require some points to be black, so that no matter which point (including the relevant side) after the removal can be successful so that all the remaining points can reach any one of the black point, the pigment is not much, the less the better, and the output of a few points and how many kinds of coating.

Ideas:

To make an arbitrary withdrawal of a point can make other points can reach the black point, then the points of the two connected components can guarantee this, then the same point in the double-connected component of a black point. But is each "point double connected component" applied? Too waste of paint, then shrinking into a tree, only need to apply the leaves, then the degree of 1 to find the shrinking point. But what about the kind of numbers? The points in the leaves can be blacked out except for the cut points, because if the black cut point is removed, then what about the other points in the leaves? So you can not cut points, each black point has "the number of points in the leaves-1" seed coating, all shops of the coating method is the 2nd result.

Special case, because the connection graph is given and there are at least 2 points, there may be no cut point (only 1 points of the two connected components), then directly black two, in case a black spot is removed.

  This problem can occur with up to 100,000 consecutive points, and DFS will explode. In C + + can be manually open the stack, under the g++ is unclear how to open.

1 #pragmaComment (linker, "/stack:102400000,102400000")//Open Stack2 //#include <bits/stdc++.h>3#include <iostream>4#include <cstdio>5#include <cstring>6#include <algorithm>7#include <vector>8#include <unordered_map>9#include <stack>Ten #defineLL Long Long One #definePII pair<int,int> A using namespacestd; - Const intn=100000+5; - Const intinf=0x7f7f7f7f; the intUp ; - intLow[n], dfn[n]; - BOOLIscut[n]; - intDfn_clock, bcc_cnt, bcc_no[n]; +unordered_map<int,int>Mapp; -stack< PII >Stac; +vector<int>Bcc[n], vect[n]; A  at voidDFS (intXintFar//Tarjan - { -dfn[x]=low[x]=++Dfn_clock; -  -     intChd=0; -      for(intI=0; I<vect[x].size (); i++) in     { -         intt=Vect[x][i]; to         if(!Dfn[t]) +         { -chd++; the Stac.push (Make_pair (x,t)); * DFS (t,x); $low[x]=min (low[x], low[t]);Panax Notoginseng             if(low[t]>=Dfn[x]) -             { theiscut[x]=true;//need to mark cut points +bcc[++bcc_cnt].clear (); A                  while(true) the                 { +                     intA=Stac.top (). First; -                     intb=Stac.top (). Second; $ Stac.pop (); $                     if(bcc_no[a]!=bcc_cnt) -                     { - Bcc[bcc_cnt].push_back (a); thebcc_no[a]=bcc_cnt; -                     }Wuyi                     if(bcc_no[b]!=bcc_cnt) the                     { - Bcc[bcc_cnt].push_back (b); Wubcc_no[b]=bcc_cnt; -                     } About                     if(a==x&&b==t) Break; $                 } -             } -         } -         Else if(Dfn[t]<dfn[x] && t!=Far ) A         { + Stac.push (Make_pair (x,t)); thelow[x]=min (low[x],dfn[t]); -         } $     } the     if(chd==1&&far==0) iscut[x]=false;//Root the } the  the voidFIND_BCC (intCase ) - { inmemset (Low,0,sizeof(Low)); thememset (DFN,0,sizeof(DFN)); thememset (Iscut,0,sizeof(Iscut)); Aboutmemset (Bcc_no,0,sizeof(Bcc_no)); the  theDfn_clock=bcc_cnt=0; the      for(intI=1; i<=up; i++)if(!dfn[i]) DFS (I,0);//Deep Search +LL ans1=0, ans2=1; -  the      for(intI=1; i<=bcc_cnt; i++)//What is the statistical degree?Bayi     { the         intCnt=0; the          for(intj=0; J<bcc[i].size (); J + +)if(Iscut[bcc[i][j]]) cnt++;//the degree of the connected component I is counted with a cut point.  -         if(cnt==1) ans1++, Ans2*=bcc[i].size ()-1; -     } the     if(bcc_cnt==1) ans1=2, ans2= (LL) bcc[1].size () * (bcc[1].size ()-1)/2; theprintf"Case %d:%lld%lld\n", Case, ans1, ans2); the } the  -  the intMain () the { theFreopen ("Input.txt","R", stdin);94     intA, B, N, j=0; the      while(SCANF ("%d",&N), N) the     { the mapp.clear ();98          for(intI=1; i<n; i++) vect[i].clear (); Aboutup=0; -          for(intI=0; i<n; i++)101         {102scanf"%d%d",&a,&b);103             if(!mapp[a]) mapp[a]=++Up ;104             if(!mapp[b]) mapp[b]=++up;//the dot number is reduced to continuous the 106 Vect[mapp[a]].push_back (Mapp[b]);107 Vect[mapp[b]].push_back (Mapp[a]);108         }109FIND_BCC (+ +)j); the     }111     return 0; the}
AC Code

HDU 3844 Mining Your Own Business (cut point, warp, open stack, classic)

Related Article

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.