stack<int>sp;
int tot,cnt;

int scc[114514],dfn[114514],low[114514];
void tarjan(int i){
	dfn[i] = low[i] = ++tot;
	instack[i] = 1;
	sp.push(i);
	for(auto x : v[i]){
		if(!vis[x])
		{
			tarjan(x); 
			low[i] = min(low[i],low[x]); 
		}else if(instack[x]){
			low[i] = min(low[i],dfn[x]);
		}
	}
	if(low[i] == dfn[i])
	{
		++cnt;
		while(sp.top()!= i )
		{
			scc[sp.top()] = cnt;
			instack[sp.top()]=  0;
			sp.pop();
		}
		scc[i]=cnt;
		instack[i] =  0;
		sp.pop();
	}
}