Company: UiPath_25july
Difficulty: medium
You are given a directed graph that represents a network. The graph has n nodes numbered from 1 to n and exactly n - 1 directed edges. The i -th edge goes from node g_from[i] to node g_to[i] . If the direction of every edge is ignored, the graph is a single tree (it is connected and has no cycles). You may pick any node to be the root. Once the root is fixed, you must reverse the direction of as many edges as necessary so that every edge points away from the root — that is, along every path leaving the root, each edge is traversed in its own direction. Different root choices may require reversing a different number of edges. Find the root choice that minimizes the number of edge reversals, and return that minimum number. Input Format The first line contains a single integer n , the number of nodes. Each of the next n - 1 lines contains two space-separated integers u and v , describing a directed edge from u to v . Output Format Print a single integer: the minimum number of edge reversa