You are given a directed tree with n nodes labeled from 1 to n. The tree contains n - 1 directed edges, where the edge points from from[i] to to[i].
You may choose any node as the root. After choosing the root, you may reverse some edges so that every edge points away from the root.
Return the minimum number of edge reversals needed over all possible choices of the root.
Constraints:
- 1 ≤
n≤ - 1 ≤
from[i],to[i]≤n - There is at most one edge between any two nodes
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected