UVAlive5135 Mining Your Own Business (BCC)

Source: Internet
Author: User

Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19845

Ideas

Point-double connected component.

To find the BCC, the optimal solution for each BCC is to place an escape device in each BCC with only one cut point.

Code

1#include <cstdio>2#include <cstring>3#include <stack>4#include <vector>5#include <iostream>6#include <cstdlib>7 #definefor (A,B,C) for (int a= (b);a< (c); a++)8 using namespacestd;9 TentypedefLong LongLL; One Const intMAXN =100000+Ten; A  - structedge{intu,v; - }; the  - intpre[maxn],iscut[maxn],bccno[maxn],dfs_clock,bcc_cnt; -vector<int>G[MAXN],BCC[MAXN]; -  +Stack<edge>S; -  + intDfsintUintFA) { A     intlowu=pre[u]=++Dfs_clock; at     intCh=0; -      for(intI=0; I<g[u].size (); i++) { -         intv=G[u][i]; -Edge e=(Edge) {u,v}; -         if(!Pre[v]) { - S.push (e); inch++; -             intlowv=DFS (v,u); tolowu=min (LOWU,LOWV); +             if(lowv>=Pre[u]) { -iscut[u]=1; thebcc_cnt++; Bcc[bcc_cnt].clear (); *                  for(;;) { $Edge x=S.top (); S.pop ();Panax Notoginseng                     if(bccno[x.u]!=bcc_cnt) Bcc[bcc_cnt].push_back (x.u), bccno[x.u]=bcc_cnt; -                     if(bccno[x.v]!=bcc_cnt) Bcc[bcc_cnt].push_back (X.V), bccno[x.v]=bcc_cnt; the                     if(X.u==u && x.v==v) Break; +                 } A             } the         } +         Else if(Pre[v]<pre[u] && v!=FA) { -S.push (e); lowu=min (lowu,pre[v]); $         } $     } -     if(fa<0&& ch==1) iscut[u]=0; -     returnLowu; the } - voidFIND_BCC (intN) {Wuyimemset (PRE,0,sizeof(pre)); thememset (Iscut,0,sizeof(Iscut)); -memset (Bccno,0,sizeof(BCCNO)); WuDfs_clock=bcc_cnt=0; -      for(intI=0; i<n;i++) About         if(!pre[i]) DFS (i,-1); $ } -  - intn,m,kase; -  A intMain () { +      while(SCANF ("%d", &m) &&m) { the         intu,v; -n=0; $          for(intI=0;i<2*m;i++) g[i].clear (); the          for(intI=0; i<m;i++) { thescanf"%d%d",&u,&v); theU--, v--; then=Max (N,max (u,v)); - G[u].push_back (v); in g[v].push_back (u); the         } the          while(!S.empty ()) S.pop (); About          the FIND_BCC (n); the          theLL ans1=0, ans2=1; +          for(intI=1; i<=bcc_cnt;i++) { -             intCnt=0; the              for(intj=0; J<bcc[i].size (); j + +)Bayi                 if(Iscut[bcc[i][j]]) cnt++; the             if(cnt==1) { theans1++; Ans2*= (Long Long) (Bcc[i].size ()-1); -             } -         } the         if(bcc_cnt==1) { theans1=2; ans2=bcc[1].size () * (bcc[1].size ()-1)/2; the         } theprintf"Case %d:%lld%lld\n",++kase,ans1,ans2); -     } the     return 0; the}

UVAlive5135 Mining Your Own Business (BCC)

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.