Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return -1.0.
Example: Given a / b = 2.0, b / c = 3.0. queries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? . return [6.0, 0.5, -1.0, 1.0, -1.0 ].
The input is: vector<pair<string, string>> equations, vector<double>& values, vector<pair<string, string>> queries , where equations.size() == values.size(), and the values are positive. This represents the equations. Return vector<double>.
int n = equations.size(); for (int i = 0; i < n; ++i) { if (name_to_node.find(equations[i].first) == name_to_node.end()) name_to_node[equations[i].first] = new Node(equations[i].first); if (name_to_node.find(equations[i].second) == name_to_node.end()) name_to_node[equations[i].second] = new Node(equations[i].second);