Company: Zomato_1aug
Difficulty: medium
Office Distribution Problem Description A country is represented as a tree of linked cities. They want to construct one of m kinds of offices in every city. Adjacent cities or cities within a distance of two should not have the same type of office. Determine the number of ways to distribute the office types across all cities. The tree contains g_nodes cities where: Cities are labeled from 1 to g_nodes . Cities are linked by g_nodes - 1 bidirectional roads. The i th road connects the cities g_from[i] and g_to[i] . Determine the number of ways to distribute the office types across all cities. Return the result modulo (10 9 + 7). Function Description Complete the function getTotalWays in the editor with the following parameters: int m : the number of service types available int g_nodes : the number of cities int g_from[g_nodes-1] : one end of each edge int g_to[g_nodes-1] : the other end of each edge Returns: int : the number of ways to build the offices, modulo (10 9 + 7) Examples Exampl