Poj1236network of schools Tarjan nude questions

Source: Internet
Author: User

Actually, it's a tarjan template.

When the output of the note is the number of points in the degree of 0 and max (number of degrees 0, the number of degrees 0), in the n=1 when the special 0 can be

--The future diagram theory should be gradually templated, easy to use

1#include <cstdio>2#include <iostream>3 using namespacestd;4 structE5 {6     int  from, To,next;7} e[100001];8 intenum=0, sttop=0;9 intfirst[101];Ten intdfn[101],low[101]; One BOOLque[101]; A inttar[101]; - intSum,n,_ans,ans; - intDF; the intnum[101]; - intst[101]; - voidAddint  from,intto ) - { + E New; -New. from= from; +new.to=to ; Anew.next=first[ from]; ate[++enum]=New; -first[ from]=Enum; - } - voidTarjan_dfs (intu) - { -st[++sttop]=u; in     intv; -que[u]=1; todfn[u]=low[u]=++DF; +      for(intI=first[u];i;i=e[i].next) -     { thev=e[i].to; *         if(dfn[v]==0) $         {Panax Notoginseng Tarjan_dfs (v); -low[u]=min (low[u],low[v]); the         } +         Else A         if(Que[v]) thelow[u]=min (low[u],dfn[v]); +     } -     if(dfn[u]==Low[u]) $     { $sum++; -          Do -         { thev=st[sttop--]; -que[v]=0;Wuyitar[v]=sum; the} while(u!=v); -     } Wu } - intTarjan () About { $sum=0;d f=0; sttop=0; -      for(intI=1; i<=n;i++) -         if(!Dfn[i]) - Tarjan_dfs (i); A      for(intI=1; i<=n;i++) +first[i]=0;//empty the original edge the      for(intI=1; i<=enum;i++) -     if(Tar[e[i]. from]!=tar[e[i].to]) $     { theE[i]. from=tar[e[i]. from]; thee[i].to=tar[e[i].to]; theE[i].next=first[e[i]. from]; theFirst[e[i]. from]=i; -num[e[i].to]++; in     } the     returnsum; the } About voidDfsintk) the { the     if(First[k]) the          for(intI=first[k];i;i=e[i].next) + DFS (e[i].to); -     Else the     if(!Que[k])Bayi     { the_ans++; theque[k]=1; -     } - } the intMain () the { thescanf"%d",&n); the      for(intI=1; i<=n;i++) -     { the         intK; thescanf"%d",&k); the          while(k>0)94         { the Add (i,k); thescanf"%d",&k); the         }98     } Aboutn=Tarjan (); -      for(intI=1; i<=n;i++)101que[i]=0;102      for(intI=1; i<=n;i++)103     if(!Num[i])104     { theans++;106 DFS (i);107     }108printf"%d\n%d\n", ans,n==1?0: Max (Ans,_ans));109     return 0; the}

Poj1236network of schools Tarjan nude questions

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.