You are given equations of the form A / B = value as equations[i] = [A, B] with values[i], where every variable is a string and the equations never contradict each other. Answer each query [C, D] with the value of C / D, or -1.0 if it cannot be determined.
- A query about a variable that never appears in any equation is
-1, even x / x - A known variable divided by itself is
1 - Answers are compared with a tolerance of 0.00001
- Solve it with a union-find that stores, for every variable, its ratio to its parent (no DSU class is provided: the ratio must live in the structure)
- A recursive
find follows the whole chain, so merge the smaller set under the larger