#include #include #include #include #include #include #include using namespace std; int t, n; vector parent, sz; vector < pair > point; class comparator { public: bool operator()(pair> &x, pair> &y) { return x.first > y.first; } }; priority_queue >, vector>>, comparator> pq; void initialize() { point.clear(); parent.clear(); sz.clear(); sz.resize(n, 1); parent.resize(n); for (int i = 0; i < n; i++) parent[i] = i; } double dist(double a, double b, double c, double d) { return sqrt(((a - c)*(a - c)) + ((b - d)*(b - d))); } void makeGraph() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(i != j) { pq.push({ dist(point[i].first, point[i].second, point[j].first, point[j].second), {i, j} }); } } } } int find(int x) { if (x == parent[x]) { return parent[x]; } else { return parent[x] = find(parent[x]); } } bool merge(int x, int y) { int px = find(x); int py = find(y); if(px == py) { return false; } else { if(sz[px] < sz[py]) { swap(px, py); } parent[py] = px; sz[px] += sz[py]; return true; } } double mst() { double how = 0; int count = 0; while (!pq.empty()) { pair< double, pair > top = pq.top(); pq.pop(); if(count < n - 1 && merge(top.second.first, top.second.second)) { how += top.first; count++; } } return how; } int main() { bool ok = false; cin >> t; while (t--) { cin >> n; initialize(); for (int i = 0; i < n; i++) { double x, y; cin >> x >> y; point.push_back({ x,y }); } makeGraph(); if (!ok) ok = true; else cout << endl; printf("%.2f\n", mst()); } }