Medium
,Array
,Graph
,DFS
,BFS
You are given an array of variable pairs equations
and an array of real numbers values
, where equations[i] = [Ai, Bi]
and values[i]
represent the equation Ai
/ Bi
= values[i]
. Each Ai
or Bi
is a string that represents a single variable.
You are also given some queries
, where queries[j]
= [Cj, Dj]
represents the jth query where you must find the answer for Cj
/ Dj
= ?.
Return the answers to all queries. If a single answer cannot be determined, return -1.0
.
Note: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.
Example 1:
Example 2:
Example 3:
Constraints:
equations.length
<= 20equations[i].length
== 2Ai.length
, Bi.length
<= 5values.length
== equations.length
values[i]
<= 20.0queries.length
<= 20queries[i].length
== 2Cj.length
, Dj.length
<= 5Ai
, Bi
, Cj
, Dj
consist of lower case English letters and digits.