Calculate the weights between the values and then the Minimum Spanning Tree.
# Include <cstring> # include <string> # include <cstdio> # include <algorithm> # include <cmath> # include <map> # include <deque> using namespace STD; struct point {Double X, Y ;}; struct edge {int U, V; double W; void F (int I, Int J, Double K) {u = I; V = J; W = K;} bool operator <(const edge & A) const {return W <. W ;}}; edge e [10001]; point P [101]; int f [101]; int n, l; int find2 (int x) {return f [x] = x? X: F [x] = find2 (F [x]);} double solve () {for (INT I = 0; I <n; I ++) f [I] = I; double S = 0; For (INT I = 0; I <L; I ++) {int A = find2 (E [I]. u), B = find2 (E [I]. v); if (! = B) {f [a] = B; S + = E [I]. W ;}} return s ;}int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d ", & N); For (INT I = 0; I <n; I ++) {scanf ("% lf", & P [I]. x, & P [I]. y);} l = 0; For (INT I = 0; I <n; I ++) for (Int J = I + 1; j <n; j ++) {e [L ++]. f (I, j, SQRT (P [I]. x-P [J]. x) * (p [I]. x-P [J]. x) + (P [I]. y-P [J]. y) * (p [I]. y-P [J]. y);} Sort (E, E + l); printf ("%. 2lf \ n ", solve (); If (t) puts ("");}}