Code Question
Amazon manages a network of warehouses connected as a weighted tree with network_nodes nodes labeled from 1 to network_nodes. Each edge (u, v) has a positive integer weight network_weight, representing the transfer time between u and v. The distance between two nodes is the sum of weights along their unique path.
Given an integer batch_time, compute for every warehouse c the number of ordered pairs of other warehouses (a, b) such that:
a ≠ b, a ≠ c, b ≠ c
The distances from node a to node b and from node a to node c are divisible by batch_time.
Note:
The path between node a and b is not required to pass through c. Only the distances from a to c and a to b must be divisible by batch_time.
Return an array where each element represents the number of valid ordered pairs for that warehouse.
Additional Notes
In an ordered pair, (a, b) and (b, a) are treated as different pairs.