Each entry of equations is a pair of variable names [A, B], and the number at the same index of values tells you what A / B equals. So equations[i] = ["p", "q"] with values[i] = 2.0 means p / q = 2.0.
Each entry of queries is a pair [C, D] asking for the value of C / D. Answer every query, in order, using only what the equations let you work out:
C to D, possibly through a chain of other variables, return the value of C / D.-1.0. That includes any query that names a variable which appears in no equation, even X / X for such a variable.An answer within 10⁻⁵ of the true value counts as correct.
Following the chain, p / s = (p / q) × (q / r) × (r / s) = 2 × 0.5 × 8 = 8. Since q / s = 0.5 × 8 = 4, the reverse s / q is 1 / 4. No equation mentions t, so the last query has no answer.
a1 and c belong to two separate groups that no equation connects, so a1 / c can't be worked out. d does appear in an equation, so d / d is 1.
z appears in no equation, so even z / z is -1.0.
Constraints
1 <= equations.length <= 20equations[i].length == 2values.length == equations.length0.0 < values[i] <= 20.01 <= queries.length <= 20queries[i].length == 2Treat every variable as a node and every equation a / b = k as two weighted edges: a → b with weight k and b → a with weight 1 / k. A query asks whether two nodes are connected and, if so, what the product of the weights along a path between them is.