Comments

I want to share a way to construct the shallowest decomposition tree other than considering chains(maybe easier to understand?). A $$$O(n^2)$$$ way is finding the maximum label in the subtree each time. But if we consider merging nodes with the smallest label, the total number of manipulations will be $$$O(n)$$$. This ugly code assumes $$$label[i]=i$$$.

for(int u=1;u<=n;u++)
{
	for(auto v:G[u])
	{
		if(v>u||find(u)==find(v)) continue;
		T[u].push_back(find(v));
		fa[find(v)]=find(u);
	}
}