HAOI2006 Popular cattle (strong Unicom component)

Source: Internet
Author: User

After the strong Unicom component is determined to determine the degree of 0 points there are several, there are 1 output this component of the number of points, otherwise output 0;

varI,j,n,m,x,y,ans1,ans2,t,cnt,top:longint; HEAD,NEXT,GO,STA,INP:Array[0..50010] ofLongint; Low,dfn,scc,s:Array[0..10000] ofLongint; Flag:Array[0..10000] ofBoolean; functionmin (x,y:longint): Longint; begin     ifX<y ThenExit (x)Elseexit (y); End;procedureDFS (k:longint);varI,v,x:longint;beginInc (T);d Fn[k]:=t;low[k]:=T; Inc (top); Sta[top]:=k; I:=Head[k]; whileI<>0  Do  beginV:=Go[i]; ifdfn[v]=0  Then    beginDfs (v); LOW[K]:=min (low[k],low[v]); End   Else ifscc[v]=0  Thenlow[k]:=min (low[k],dfn[v]); I:=Next[i]; End; ifLOW[K]=DFN[K] Then  beginInc (CNT); Repeatx:=sta[top];inc (s[cnt]);    Dec (top); SCC[X]:=CNT; ifX=k ThenBreak ; untilfalse; End; End;procedureInit;beginreadln (n,m); fori:=1  toM Do  beginreadln (x, y); Go[i]:=y;next[i]:=head[x];head[x]:=i; End;  fori:=1  toN Do  ifdfn[i]=0  ThenDFS (i);End;proceduremain;beginFillchar (flag,sizeof (flag), true); fori:=1  toN Do  beginJ:=Head[i];  whileJ<>0  Do     beginx:=Go[j]; ifScc[x]<>scc[i] Thenflag[scc[i]]:=false; J:=Next[j]; End; End;  fori:=1  toCnt Do  ifFlag[i] Then   beginInc (ANS1); Ans2:=S[i]; End; ifans1=1  ThenWriteln (ANS2)ElseWriteln (0); End;begininit; main;End.

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.