"Strong Unicom component reduction" "Tarjan" bzoj1051 [HAOI2006] Popular Cattle

Source: Internet
Author: User

is to see if there are some points that can be reached from any other point

Theorem: The only point in a direction-free graph with a degree of 0 can be reached from any point.

So, if the point is zero (strong unicom component), the answer is the degree of the midpoint of the strong unicom component.

If not unique, the answer is 0, easy to pass.

Code (lazy Tarjan, used two times Dfs):

1#include <cstdio>2#include <cstring>3#include <vector>4 using namespacestd;5vector<int>order;6 intv[100001],first[100001],next[100001],en;7 inta[50001],b[50001],scc[10001],num[10001],sum,chu[10001];8 BOOLvis[10001];9 intn,m;TenInlinevoidAddedge (Const int&u,Const int&AMP;V) {v[++en]=v;next[en]=first[u];first[u]=en;} One voidClear () A { -memset (V,0,sizeof(v)); -memset (First,0,sizeof(first)); theMemset (Next,0,sizeof(next)); -en=0; - } - voidDfsintcur) + { -vis[cur]=true; +      for(intI=first[cur];i;i=Next[i]) A       if(!Vis[v[i]]) at DFS (V[i]); - order.push_back (cur); - } - voidDFS2 (intCurintsum) - { -vis[cur]=true; inscc[cur]=sum; -num[sum]++; to      for(intI=first[cur];i;i=Next[i]) +       if(!Vis[v[i]]) - DFS2 (v[i],sum); the } * voidScc () $ {Panax Notoginseng      for(intI=1; i<=n;i++) -       if(!Vis[i]) the DFS (i); +memset (Vis,false,sizeof(VIS)); Clear (); A      for(intI=1; i<=m;i++) Addedge (B[i],a[i]); the     intsz=order.size (); +      for(inti=sz-1; i>=0; i--) -       if(!Vis[order[i]]) $DFS2 (order[i],++sum); $ } - intExam () - { the     intCnt=0, Record; -      for(intI=1; i<=m;i++)Wuyi       if(scc[a[i]]!=Scc[b[i]]) thechu[scc[a[i]]]++; -      for(intI=1; i<=sum;i++) Wu       if(!Chu[i]) -         { Aboutcnt++; $record=i; -           if(cnt==2) -             return 0; -         } A     returnNum[record]; + } the intResCharC; -InlineintGet () $ { theres=0; C='*';  the      while(c<'0'|| C>'9') c=GetChar (); the      while(c>='0'&&c<='9') {res=res*Ten+ (C-'0'); C=GetChar ();} the     returnRes; - } in intMain () the { theN=get (); m=Get (); About      for(intI=1; i<=m;i++) {a[i]=get (); b[i]=Get (); Addedge (A[i],b[i]);} theSCC ();p rintf ("%d\n", Exam ()); the     return 0; the}

"Strong Unicom component reduction" "Tarjan" bzoj1051 [HAOI2006] Popular Cattle

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.