Read the full problem statement at the link above. Make sure you understand what a centroid is before continuing. The definition is precise: no component can have more than nodes. The core constraint: after removing the centroid, each remaining component has at most nodes. This includes the parent direction if you are rooting the tree. Try to think of an algorithm before reading further. How would you check if a node is a centroid?
How would you find one efficiently?