vector<double> calcEquation(vector<vector<string>>& equations, vector<double>& values, vector<vector<string>>& queries) {
vector<vector<double>> graph(index, vector<double>(index, -1.0));
for(int k = 0, size = equations.size(); k < size; k++) {
int i = smap[equations[k][0]], j = smap[equations[k][1]];
graph[j][i] = 1 / values[k];
for(int k = 0, size = queries.size(); k < size; k++) {
auto it1 = smap.find(queries[k][0]);
auto it2 = smap.find(queries[k][1]);
if (it1 == smap.end() || it2 == smap.end()) {
if (queries[k][0] == queries[k][1]) {
int i = it1->second, j = it2->second;
vector<bool> visited(index, false);
if (dfs(graph, visited,i, j, res[k]) == false) {
bool dfs(vector<vector<double>> &graph, vector<bool> &visited, int s, int e, double &res) {
if (s == e) { res = 1.0; return true; }
for(int i = 0;i < graph.size(); i++) {
if (visited[i] == false && graph[s][i] > 0 && dfs(graph, visited, i, e, temp)) {
res = temp * graph[s][i];