Company: UKG_20july
Difficulty: medium
Unit Conversions Problem Description There are unit_nodes types of unit, and ( unit_nodes - 1 ) relations between them. The relations are defined using three arrays namely unit_from , unit_to and unit_weight where unit_weight[i] magnitude of type unit_to[i] equals 1 magnitude of type unit_from[i] . Given a parameter x , find the magnitude in each unit which will be equivalent to x magnitude in unit 1. For each unit, return the answer modulo (10 9 + 7). Note: The relationships between the units form a directed rooted tree, rooted at unit 1, i.e., the in-degree of every node is at most 1 (Unit 1 has in-degree 0). Examples Example 1: Consider the following input: unit_nodes = 3 , unit_from = [1, 2] , unit_to = [2, 3] , unit_weight = [2, 1] and x = 1 . The relations are: 2 magnitude of unit 2 is equivalent to 1 magnitude of unit 1. (From unit_from[0]=1, unit_to[0]=2, unit_weight[0]=2 ) 1 magnitude of unit 3 is equivalent to 1 magnitude of unit 2. (From unit_from[1]=2, unit_to[1]=3, unit_we