Recursive Land Division Question - Solved

10 Live
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

Asked in: SHARECHAT

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |