Tap here to switch tabs
Problem
Submissions

Problem: Unit Conversion I

Try to solve the Unit Conversion I problem.

Statement

There are nn units indexed from 00 to n−1n - 1. You are given a 2D2 {D} integer array conversions of size n−1n - 1, where conversions[i] = [sourceUnit_i, targetUnit_i, conversionFactor_i] indicates that 11 unit of sourceUnit_i is equivalent to conversionFactor_i units of targetUnit_i.

Return an array of length nn where the ithi {th} element is the number of units of type ii obtained from 11 unit of type 00.

Constraints:

  • 2≤n≤1052 \leq n \leq 10^5

  • conversions.length =n−1= n - 1

  • 0≤0 \leq sourceUnit_i, targetUnit_i <n< n

  • 1≤1 \leq conversionFactor_i ≤109\leq 10^9

  • It is guaranteed that unit 00 can be converted into any other unit through a unique combination of conversions without using any conversions in the opposite direction.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Unit Conversion I

Try to solve the Unit Conversion I problem.

Statement

There are nn units indexed from 00 to n−1n - 1. You are given a 2D2 {D} integer array conversions of size n−1n - 1, where conversions[i] = [sourceUnit_i, targetUnit_i, conversionFactor_i] indicates that 11 unit of sourceUnit_i is equivalent to conversionFactor_i units of targetUnit_i.

Return an array of length nn where the ithi {th} element is the number of units of type ii obtained from 11 unit of type 00.

Constraints:

  • 2≤n≤1052 \leq n \leq 10^5

  • conversions.length =n−1= n - 1

  • 0≤0 \leq sourceUnit_i, targetUnit_i <n< n

  • 1≤1 \leq conversionFactor_i ≤109\leq 10^9

  • It is guaranteed that unit 00 can be converted into any other unit through a unique combination of conversions without using any conversions in the opposite direction.