Graph Theory37 sections · 1633 units
Open in Course

Problem - Finding a Centroid

(CSES 2079)

You are given a tree with nn nodes. Find any centroid. A centroid is a node where removing it leaves no component with more than n/2\lfloor n/2 \rfloor nodes. This is the foundation of centroid decomposition. If you can find one centroid efficiently, you can recursively find all of them.

The algorithm is simple but the Core idea is useful. Let me walk you through the solution step by step. You will use this as a subroutine in all centroid decomposition algorithms.