Company: Ukg_5sep
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). Consider the following input: unit_nodes = 3 , unit_from = [1, 2] , unit_to = [2, 3] , unit_weight = [2, 1] and x = 1 . This represents a chain of conversions where Unit 1 converts to Unit 2 with weight 2, and Unit 2 converts to Unit 3 with weight 1. Specifically, 1 magnitude of unit_from[i] is equivalent to unit_weight[i] magnitudes of unit_to[i] . 1 magnitude of unit 1 is equiv