Company: Tower Research_22july
Difficulty: medium
Balanced Tree Problem Description A gardener keeps a collection of tree_nodes bowls arranged as a tree. The bowls are numbered 1 to tree_nodes , and bowl i currently holds stones[i - 1] stones. Two bowls are adjacent when an edge of the tree joins them. The arrangement is called balanced when, for every edge of the tree, the two bowls it joins differ by at most one stone. Formally, writing c[u] for the number of stones in bowl u , the arrangement is balanced when |c[u] - c[v]| <= 1 for every edge (u, v) of the tree The gardener may only add stones. Stones are never removed and never moved from one bowl to another. Any bowl may receive any number of extra stones, including none. Determine the smallest total number of extra stones that has to be added so that the arrangement becomes balanced. Input Format The first line contains two integers, tree_nodes and m , where m = tree_nodes - 1 is the number of edges. Each of the next m lines contains two integers tree_from[i] and tree_to[i] ,