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