poj1236/luogu2746 Network of schools (Tarjan)

Source: Internet
Author: User

After Tarjan, the first question is clearly the number of points with zero degrees.
Second question: Considering that there is no degree of penetration or 0 of the point of the graph strong connectivity,
So the answer is that the number of zero in the max{, the number of zero in the degree}
(The zero-out point is connected to zero, then the remaining zero is a random connection)

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineLL Long Long int5 using namespacestd;6 Const intmaxn= the, maxm=10010;7 8 LL Rd () {9LL x=0;CharC=getchar ();intneg=1;Ten      while(c<'0'|| C>'9'){if(c=='-') neg=-1; c=GetChar ();} One      while(c>='0'&&c<='9') x=x*Ten+c-'0', c=GetChar (); A     returnx*neg; - } -  the intN; - integ[maxm][2],EGH[MAXN],ECT,BEL[MAXN]; - intDFN[MAXN],LOW[MAXN],STK[MAXN],TOT,PCT,SCT; - inttin,tout; + BOOLINSTK[MAXN],inch[MAXN], out[MAXN]; -  + voidTarjan (intx) { Adfn[x]=low[x]=++tot;stk[++sct]=x;instk[x]=1; at      for(inti=egh[x];i!=-1; i=eg[i][1]){ -         intj=eg[i][0]; -         if(Instk[j]) low[x]=min (low[x],dfn[j]); -         Else if(!Dfn[j]) { -Tarjan (j); low[x]=min (low[x],low[j]); -         } in     } -     if(dfn[x]==Low[x]) { topct++; +          while(SCT) { -instk[stk[sct]]=0; thebel[stk[sct]]=pct; *             if(stk[sct--]==x) Break; $         }Panax Notoginseng     } - } the  +InlinevoidAdeg (intAintb) { Aeg[ect][0]=b;eg[ect][1]=egh[a];egh[a]=ect++; the } +  - intMain () { $     inti,j,k; $N=rd (); Memset (egh,-1,sizeof(Egh)); -      for(i=1; i<=n;i++){ -          while(j=Rd ()) adeg (i,j); the     } -      for(i=1; i<=n;i++){Wuyi         if(!Dfn[i]) Tarjan (i); the     } -      for(i=1; i<=n;i++){ Wu          for(j=egh[i];j!=-1; j=eg[j][1]){ -k=eg[j][0]; About             intii=bel[i],kk=Bel[k]; $             if(ii!=KK) { -                 inch[kk]=1; out[ii]=1; -             } -         } A} for(i=1; i<=pct;i++){ +         if(!inch[i]) tin++; the         if(! out[i]) tout++; -     } $     if(pct>1) printf ("%d\n%d", Tin,max (tin,tout)); the     Elseprintf"1\n0"); the      the}

poj1236/luogu2746 Network of schools (Tarjan)

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.