int dfn[maxn],low[maxn],belong[maxn]; bool instk[maxn]; stack<int>stk; void tarjan(int u){ dfn[u]=low[u]=++cnt; stk.push(u); instk[u]=1; int sz=gra[u].size(); for(int i=0;i<sz;i++){ int v=gra[u][i]; if(!dfn[v]){ tarjan(v); low[u]=min(low[u],low[v]); }else if(instk[v]){ low[u]=min(low[u],dfn[v]); } } if(dfn[u]==low[u]){ col++; int t; do{ t=s.top(); s.pop(); belong[t]=col; instk[t]=0; }while(t!=u) } }