Recursive Land Division Question - Solved

7 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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |