bzoj1051: [HAOI2006] Popular cattle (strong unicom)

Source: Internet
Author: User

1051: [HAOI2006] Popular cattle

Title: Portal

Exercises

Today I do a water problem ...

Strong Unicom, obviously.

Water template After statistics on the number of points in each of the strong unicom, and then statistics on the degree of ...

It is not difficult to find out that the strong connected component can be accessed by all points when and only if there is only one strong connectivity component in the 0.

specific to their own painting yy it ...

Code:

1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <cmath>5#include <algorithm>6 #defineQread (x) X=read ()7 using namespacestd;8InlineintRead ()9 {Ten     intf=1, x=0;Charch; One      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnf*x; - } the structnode - { -     intX,y,next; -}a[51000];intlen,last[11000]; + voidInsintXinty) - { +len++; Aa[len].x=x;a[len].y=y; ata[len].next=last[x];last[x]=Len; - } - intn,m,id,tp,cnt; - intbelong[11000],dfn[11000],low[11000],sta[11000]; - BOOLv[11000]; - voidDfsintx) in { -low[x]=dfn[x]=++ID; tosta[++tp]=x;v[x]=true; +      for(intk=last[x];k;k=a[k].next) -     { the         inty=a[k].y; *         if(dfn[y]==-1) $         {Panax Notoginseng dfs (y); -low[x]=min (low[x],low[y]); the         } +         Else A         { the             if(v[y]==true) +low[x]=min (low[x],dfn[y]); -         } $     } $     if(low[x]==Dfn[x]) -     { -         inti;cnt++; the          Do{ -i=sta[tp--];Wuyiv[i]=false; thebelong[i]=CNT; -} while(i!=x); Wu     } - } About intnum[11000],chu[11000]; $ intMain () - { - qread (n); Qread (m); -      for(intI=1; i<=m;i++) A     { +         intx, y; the qread (x); Qread (y); - ins (x, y); $     } theId=tp=cnt=0; thememset (dfn,-1,sizeof(DFN)); thememset (Low,0,sizeof(Low)); theMemset (Belong,0,sizeof(belong)); -memset (V,false,sizeof(v)); in      for(intI=1; i<=n;i++) the         if(dfn[i]==-1) the DFS (i); About     if(cnt==1) {printf ("%d\n", n);return 0;} thememset (NUM,0,sizeof(num)); thememset (Chu,0,sizeof(CHU)); the      for(intI=1; i<=n;i++) num[belong[i]]++; +      for(intI=1; i<=len;i++) -         if(belong[a[i].x]!=Belong[a[i].y]) thechu[belong[a[i].x]]++;Bayi     ints=0, K; the      for(intI=1; i<=cnt;i++)if(chu[i]==0) {s++;k=i;} the     if(s==1) printf ("%d\n", Num[k]); -     Elseprintf"0\n"); -     return 0; the}

Another water ...

bzoj1051: [HAOI2006] Popular cattle (strong unicom)

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.