Evaluate Division
Given equations like a/b = 2, answer queries for other ratios.
Examples
Input: [[["a","b"],["b","c"]],[2,3],[["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]]
Output: [6,0.5,-1,1,-1]
Input: [[["a","b"]],[0.5],[["b","a"],["a","b"],["a","c"]]]
Output: [2,0.5,-1]
Hints
Represent each equation as a directed edge in a graph where the edge weight is the ratio value (e.g., a/b = 2 becomes an edge from 'a' to 'b' with weight 2.0).
For queries where the start and end variables are the same, return 1.0 if the variable exists in the graph, otherwise return -1.0.
For queries involving variables not present in the graph, return -1.0 immediately without further processing.
Related Problems
Evaluate Division
Given equations like a/b = 2, answer queries for other ratios.