It's a basic implementation of centroid decomposed tree. Though after reading a while and solving a couple of problems i'm still unable to understand the necessity(and intuition) behind the centroid decomposition.The only time i think its useful is when two nodes are on two different subtree and then lca(on CD tree) can store some information about them.
For this specific problem.
In CD-tree, if two nodes have same rank,then they must have a common ancestor.