Problem
Submissions

Problem: Minimum Height Trees

Statement

You are given nn as the number of nodes and a 2D array of edges representing a tree having the following properties:

  • It is an acyclic, undirected graph containing nn nodes and n−1n-1 edges.

  • The nodes are labeled from 00 to n−1n-1.

  • An edge at the ithi^{th} index is represented as [ai,bi][a_i, b_i], which denotes that there is an undirected edge connecting the nodes aia_i and bib_i.

Your task is to find all possible root nodes that can be used to create trees of minimum height. The height of a tree is the length of the longest path from the root node to any leaf node.

Note: The order of root nodes in the result does not matter.

Constraints

  • 1≤n≤5001 \leq n \leq 500
  • edges.length ==n−1== n - 1
  • ai≠bia_i \neq b_i
  • Each edge is unique.
Problem
Submissions

Problem: Minimum Height Trees

Statement

You are given nn as the number of nodes and a 2D array of edges representing a tree having the following properties:

  • It is an acyclic, undirected graph containing nn nodes and n−1n-1 edges.

  • The nodes are labeled from 00 to n−1n-1.

  • An edge at the ithi^{th} index is represented as [ai,bi][a_i, b_i], which denotes that there is an undirected edge connecting the nodes aia_i and bib_i.

Your task is to find all possible root nodes that can be used to create trees of minimum height. The height of a tree is the length of the longest path from the root node to any leaf node.

Note: The order of root nodes in the result does not matter.

Constraints

  • 1≤n≤5001 \leq n \leq 500
  • edges.length ==n−1== n - 1
  • ai≠bia_i \neq b_i
  • Each edge is unique.