1 void tarjan(int x) 2 { 3 num++; 4 dfn[x]=low[x]=num; 5 vis[x]=true; 6 st[++top]=x; 7 for(int i=firstt[x];i;i=nextt[i]) 8 { 9 int y=to[i]; 10 if(dfn[y]==0) 11 { 12 tarjan(y); 13 low[x]=min(low[x],low[y]); 14 } 15 else if(vis[y]==true) low[x]=min(low[x],dfn[y]); 16 } 17 if(low[x]==dfn[x]) 18 { 19 int y; 20 lhy++; 21 do 22 { 23 y=st[top--]; 24 color[y]=lhy; 25 vis[y]=false; 26 sum[lhy]++; 27 }while(x!=y); 28 } 29 }