Tree centroids
Your task
An undirected tree has n nodes labeled 0..n-1 and exactly n-1 edges. Rooting the tree at a node gives it a height (the longest path from the root to any leaf). Return all root labels that minimize the tree's height (the centroids), in ascending order. For n==1 return [0]; for n==2 return both nodes. There are at most two such roots.
Examples
min_height_trees(n: int, edges: list[list[int]]) -> list[int]Example 1
Input
min_height_trees(4, [[1, 0], [1, 2], [1, 3]])Output
[1]