Here is the C++ version.

At first I was trying to solve it using original Floyd Algorithm, but then I find that, since the question requires "multiply operation" instead of the original "add operation" for the calculation of the shortest path and also original implementation uses index to denote each vertex instead of string, any of the two which could change the way of implementation significantly. Because multiplication can not be accumulated, and you cannot denote vertex using string in a vector either. Then I saw your solution, you used map instead of a 2D vector, which solved all these issues!

First, you did not check if the path is shortest or not to set dist[i][j]. This is very brilliant, because we DO NOT need shortest path here, so even the path not shortest does not matter.

Second, using map makes it very easy to know if any edges between two vertices by checking their existence in the map.

class Solution {
public:
vector<double> calcEquation(vector<pair<string, string>> equations, vector<double>& values, vector<pair<string, string>> queries) {
unordered_map<string, unordered_map<string, double>> dist;
for (int i = 0; i < equations.size(); ++i) {
auto p = equations[i];
double value = values[i];
string from = p.first, to = p.second;
dist[from][to] = value;
dist[to][from] = 1 / value;
dist[from][from] = dist[to][to] = 1.0;
}
for (auto& k : dist) {
for (auto& i : dist[k.first]) {
for (auto& j : dist[k.first]) {
dist[i.first][j.first] = dist[i.first][k.first] * dist[k.first][j.first];
}
}
}
vector<double> res;
for (auto& q : queries) {
string from = q.first, to = q.second;
if (dist.find(from) != dist.end() && dist[from].find(to) != dist[from].end()) {
res.push_back(dist[from][to]);
} else {
res.push_back(-1.0);
}
}
return res;
}
};