Company: Infoedge_23aug
Difficulty: medium
Divisible Tree Splits A company network is laid out as a tree of n offices numbered 0 to n - 1 , joined by n - 1 links. Link i joins offices edges[i][0] and edges[i][1] . Office i holds a budget of values[i] units. You are also given an integer k . You may shut down any set of links (possibly none). Every group of offices that is still connected becomes a separate region. A plan is valid when the total budget of every region is a multiple of k . Return the largest number of regions a valid plan can produce. The total of all budgets is guaranteed to be a multiple of k , so keeping every link (one region) is always valid. Function description Complete the function maxValidTreeSplit with the following parameters: int n : the number of offices int k : the divisor int edges[n - 1][2] : the links of the tree int values[n] : the budget of each office Returns int : the maximum number of regions in a valid plan. Input format Line 1: the integer n . Line 2: the integer k . Line 3: the integer x