TESTERS - Editorial

Can anybody please explain that how setters solution is O(n*log(n)).

To my understanding he is basically applying dfs on first the root, and then recursively on each of its child.

Even after centroid decomposition only the height of the tree is converted to log(n) but still the complexity seems to be nlogn(n) + (n-1)log(n-1)…

Even in balanced binary tree first the routine is applied on the root and then on each of its childs.