Question: Write the problem code in C + + & run it . Problem: Given a tree of n ( 1 < = n < =

Write the problem code in C++ & run it. Problem: Given a tree of n (1<= n <=1000) nodes labelled from 0 to n -1,
and an array of n -1 edges where an edge {a, b} indicates that
there is an undirected edge between the two nodes a and b in
the tree. Note that any node of the tree can act as a root.
The height of a rooted tree is the number of edges on the
longest path between the root and a leaf. When you select a
node x as the root, the resultant tree has height h(x). Among all
possible rooted trees, those with the minimum height are
called minimum height trees (MHTs). Print the roots of
all MHTs. Constraints:
1<= n <=20000
0<= a, b < n
a != b
All the pairs {a, b} are distinct.
The given input is guaranteed to be a tree.
Input: n =4
{1,0},{1,2},{1,3}
Output: {1}
Input: n =6
{3,0},{3,1},{3,2},{3,4},{5,4}
Output: {3,4}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!