Recursive Land Division Question - Solved
Recursive Land Division
A country consists of N regions, each containing a specific number of towns. The government has decided to split the country into two separate nations in a way that minimizes the absolute difference between the total number of towns in each new nation.
Each region is connected to another region through roads, forming a tree structure (i.e., an undirected connected graph with N-1 edges and no cycles).
Your task is to determine the minimum possible absolute difference in the number of towns between the two new nations.I represents a bidirectional road connecting region u and region v.
Returns
int β The minimum absolute difference in the number of towns
between the two new nations after removing exactly one road.
Input Format
- The first line contains one integer, N (the number of regions).
- The second line contains N space-separated integers representing the towns array.
- The next N-1 lines each contain two integers, u and v,
representing a bidirectional road between regions u and v.
Output Format
A single integer representing the minimum possible absolute difference
in the number of towns between the two new nations.
Constraints