#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack > #include <cstdlib> #include <cmath> #include <set> #include <map> #include <vector># Include <cstring> #define INF 100000000using namespace Std;int n,m;int x[1005];int y[1005];int fa[1005];struct node {int X,y,w;bool operator < (const node& a) Const{return w > a.w;}}; int fun (int x) {return fa[x] = = x "X:fa[x] = Fun (Fa[x]);} int main () {while (CIN >> N) {for (int i = 1;i <= n;i++) {scanf ("%d%d", &x[i],&y[i]);} priority_queue<node> que;for (int i = 1;i <= n;i++) {for (int j = 1;j <= n;j++) {if (i = = j) Continue;node a;a.x = I;A.Y = J;A.W = (X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j]); Que.push (a);}} for (int i = 1;i <= n;i++) {Fa[i] = i;} int m;cin >> m;for (int i = 0;i < m;i++) {int a,b;scanf ("%d%d", &a,&b); Fa[fun (a)] = fun (b);} DOUBLE ret = 0;while (!que.empty ()) {Node A = Que.top (); Que.pop ();a.x)! = Fun (A.Y)) {ret + sqrt (A.W); Fa[fun (a.x)] = Fun (A.Y);}} printf ("%.2f\n", ret);} return 0;}
UVA 10397 Connect the Campus Kruskal algorithm variants