Uvalive 5135 Mining Your Own Business Dual connected component 2011final

Source: Internet
Author: User

Test instructions:n tunnels are connected by a number of points, each of which links two connection points. There is a maximum of one tunnel between any two connection points. The task is to install as few Taiping Wells and escape devices as possible in these connection points, so that no matter which connection point collapses, workers can escape from other Taiping Wells for minimum installation quantities and solutions.

Idea: in fact, the subject is equivalent to in an undirected graph, coated as little as possible black spots, so that arbitrarily delete which points, each connected component at least one black point. Since there is at most one common point for different connected components, it must be a cut point. It can be found that the black cut point is not cost-effective, and in a point-the double-connected component of the black two dark spots are not cost-effective. So only when the point-to-double connectivity component has only one cut point, it needs to be applied, and it is a non-cut point to be blackened.

2011 Final question, the idea is not very good understand, with the practice again yy a bit to understand

1 //struct ID is used to reduce the number, a little discrete effect. But commented out after a short run time, AC2#include <cstdio>3#include <stack>4#include <vector>5#include <map>6#include <algorithm>7#include <cstring>8 using namespacestd;9typedefLong LongLL;Ten  One structEdge { A     intu, v; - }; -  the Const intMAXN =100000+Ten; - intPRE[MAXN], ISCUT[MAXN], BCCNO[MAXN], Dfs_clock, bcc_cnt;//the bccno of the top cut is meaningless. -vector<int>G[MAXN], BCC[MAXN]; -  +Stack<edge>S; -  + intDfsintUintFA) { A     intLowu = Pre[u] = + +Dfs_clock; at     intChild =0; -      for(inti =0; I < g[u].size (); i++) { -         intv =G[u][i]; -Edge e =(Edge) { - u, v -         }; in         if(!pre[v]) {//No access to V - S.push (e); tochild++; +             intLOWV =Dfs (v, u); -Lowu = min (Lowu, LOWV);//update yourself with the low function of the descendant the             if(LOWV >=Pre[u]) { *Iscut[u] =true; $bcc_cnt++;Panax Notoginseng bcc[bcc_cnt].clear (); -                  for(;;) { theEdge x =s.top (); + S.pop (); A                     if(BCCNO[X.U]! =bcc_cnt) { the 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; -                 }Wuyi             } the}Else if(Pre[v] < Pre[u] && v! =FA) { - S.push (e); WuLowu = min (Lowu, pre[v]);//update yourself with a reverse edge -         } About     } $     if(FA <0&& Child = =1) Iscut[u] =0; -     returnLowu; - } -  A //struct ID { + //Map<int, int> m; the //int cnt; - //ID (): CNT (0) {} $ //int get (int x) { the //if (!m.count (x)) m[x] = cnt++; the //return m[x]; the //    } the //}; -  in intMain () { the     intKase =0, N; the      while(SCANF ("%d", &n) = =1&&N) { Aboutmemset (PRE,0,sizeof(pre)); thememset (Iscut,0,sizeof(Iscut)); thememset (Bccno,0,sizeof(BCCNO)); the          for(inti =0; I < n2; i++) g[i].clear (); +Dfs_clock = bcc_cnt =0; -  the //ID ID;Bayi          for(inti =0; I < n; i++) { the             intu, v; thescanf"%d%d", &u, &v); - //u = id.get (u); - //v = id.get (v); theu--; thev--; the G[u].push_back (v); the g[v].push_back (u); -         } theDfs0, -1);//The s is guaranteed to be empty after the call, so do not empty the  theLL ans1 =0, Ans2 =1;94          for(inti =1; I <= bcc_cnt; i++) { the             intcut_cnt =0; the              for(intj =0; J < Bcc[i].size (); J + +) the                 if(Iscut[bcc[i][j]]) cut_cnt++;98             if(cut_cnt = =1) { Aboutans1++; -Ans2 *= (LL) (Bcc[i].size ()-cut_cnt);101             }102         }103         if(bcc_cnt = =1) {104ANS1 =2; theAns2 = bcc[1].size () * (bcc[1].size ()-1) /2;106         }107printf"Case %d:%lld%lld\n", ++Kase, ans1, ans2);108     }109     return 0; the}
View Code

Uvalive 5135 Mining Your Own Business Dual connected component 2011final

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.