POJ 1236 Strong Unicom components

Source: Internet
Author: User

Link:

http://poj.org/problem?id=1236

Code:
 to intindex =0; + intLOW[MAXN], DFN[MAXN]; - intVIS[MAXN], BEL[MAXN]; the VI G[MAXN]; *stack<int>S; $ intscc_cnt;Panax Notoginseng  - voidTarjan (intu) { theDfn[u] = Low[u] = + +index; +S.push (U); Vis[u] =1; ARep (I,0, G[u].size ()) { the         intv =G[u][i]; +         if(!Dfn[v]) { - Tarjan (v); $Low[u] =min (Low[u], low[v]); $         } -         Else if(Vis[v]) low[u] =min (Low[u], dfn[v]); -     } the     if(Low[u] = =Dfn[u]) { -scc_cnt++;Wuyi          while(1) { the             intnow =S.top (); S.pop (); -Vis[now] =0; WuBel[now] =scc_cnt; -             if(now = = u) Break; About         } $     } - } -  - intN; A int inch[MAXN], out[MAXN]; +  the voidSCC () { -index = SCC_CNT =0; $memset (DFN,0,sizeof(DFN)); theRep (I,0, N)if(!Dfn[i]) Tarjan (i); the } the  the intMain () { -CIN >>N; in     intA; theRep (I,0, N) while(Cin >> A, a) G[I].PB (A-1); the SCC (); About     if(scc_cnt = =1) { thecout <<1<< Endl <<0<<Endl; the         return 0; the     } +Rep (U,0, N) Rep (I,0, G[u].size ()) { -         intv =G[u][i]; the         if(Bel[u]! =Bel[v]) {Bayi              out[bel[u]]++; the             inch[bel[v]]++; the         } -     } -     intIn_tot =0, Out_tot =0; theRep (I,1, scc_cnt +1) { the         if(!inch[i]) in_tot++; the         if(! out[i]) out_tot++; the     } -cout << in_tot << endl << max (In_tot, Out_tot) <<Endl; the     return 0; the}

POJ 1236 Strong Unicom components

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.