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