const int MAXN = 8001, MAXM = 8001; int head[MAXN], next[MAXM], last[MAXM], lineNum = 0; void add(int x,int y){ lineNum++, next[lineNum] = head[x], last[lineNum] = y, head[x] = lineNum; } vector<int> own[MAXN]; int vis[MAXN], bel[MAXN], st[MAXN], dfn[MAXN], low[MAXN], deep = 0, cnt = 0; void tarjan(int x){ vis[x] = 1; low[x] = dfn[x] = ++deep; st[++st[0]] = x; for(int l=head[x]; l; l=next[l]){ int y = last[l]; if(vis[y] == 0) tarjan(y), low[x] = min(low[x], low[y]); else if(vis[y] == 1) low[x] = min(low[x], dfn[y]); } if(dfn[x] == low[x]){ ++cnt; do{ bel[st[st[0]]] = cnt; own[cnt].push_back(st[st[0]]); vis[st[st[0]]] = 2; }while(st[st[0]--] != x); } }