const int N=1000+5; int head[10*N],pos; struct Edge { int to,nex; }edge[10*N]; int dfn[N],low[N],tot,vis[N],ind,Stack[N],cnt,belong[N]; int init() { CLR(head,0); CLR(dfn,0); CLR(low,0); CLR(vis,0); CLR(Stack,0); CLR(belong,0); cnt=ind=tot=pos=0; } void tarjan(int x) { dfn[x]=low[x]=++tot; Stack[++ind]=x; vis[x]=1; for(int i=head[x];i;i=edge[i].nex) { int v=edge[i].to; if(!dfn[v]) { tarjan(v);low[x]=min(low[x],low[v]); } else if(vis[v]) low[x]=min(low[x],low[v]); } if(low[x]==dfn[x]) { cnt++; int v; do { v=Stack[ind--]; vis[v]=0; belong[v]=cnt; } while(x!=v); } }