#include #include #include #include #include #include #include using namespace std; // To output a matrix ostream & operator<<(ostream & os, vector< vector< long double > > & rhs) { for (int i = 0; i > & D, vector< vector< long double > > & W) { int n = W.size(); D = W; for (int k = 0; k < n; k++) { for (int i = 0; i pid; // planet name to id map vector planets; // planet names vector p; // planet positions vector< vector< long double> > D, W; // Distances and Weights int main() { int cases, c = 1; cin >> cases; while (cases--> 0) { int n, w; // Read in the planet positions cin >> n; planets.clear(); planets.resize(n); // planet names p.clear(); p.resize(n); // planet positions pid.clear(); // planet name to id map for (int i = 0; i> planets[i] >> p[i].x >> p[i].y >> p[i].z; pid[planets[i]] = i; } // Read in the wormholes and set the shortcuts W.clear(); W.resize(n); for (int k = 0; k < n; k++) W[k].resize(n, -1.0); cin >> w; string wstart, wend; for (int i = 0; i> wstart >> wend; W[pid[wstart]][pid[wend]] = 0.0; } // Setup the weight matrix between every pair of planets for (int i = 0; i> q; for (int i = 0; i> wstart >> wend; cout << "The distance from " << wstart << " to " << wend << " is " << fixed << setprecision(0) << round(D[pid[wstart]][pid[wend]]) << " parsecs." << endl; } } return 0; }