← 返回 apple 的题目列表Unit Conversion II
类型:online_judge
There are n unit types numbered from 0 to n - 1, where unit 0 is the base unit.
You are given conversions, where each entry [source, target, factor] means:
One unit of source is equal to factor units of target.
The conversions form a tree rooted at unit 0 and cover every unit. Every unit other than 0 is reachable from unit 0 through conversion relationships.
Return an array ans where ans[i] is the number of units of type i equivalent to one unit of type 0. Return every value modulo 10^9 + 7.
Example
Input: n = 4
conversions = [[0,1,2],[1,2,3],[1,3,5]]
Output: [1,2,6,10]
Constraints
1 <= n <= 10^5
conversions.length = n - 1
1 <= factor <= 10^9
The conversion graph is valid and covers all units.
Example
Input
4
0 1 2
1 2 3
1 3 5
Output
1 2 6 10