Uva - 10034 - Freckles

——>>白白净净的最小生成树。

#include <cstdio>
#include <cmath>
#include <queue>

using namespace std;

const int maxn = 100 + 10;
int n, fa[maxn];

struct Point{
double x;
double y;
}p[maxn];

double Dis(Point A, Point B){
return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
}

struct node{
int u;
int v;
double dis;
bool operator < (const node& e) const{
return dis > e.dis;
}
};

scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
}

int Find(int x){
return fa[x] == x ? x : fa[x] = Find(fa[x]);
}

bool Union(int x, int y){
int newx = Find(x);
int newy = Find(y);
if(newx == newy) return 0;
fa[newy] = newx;
return 1;
}

void init(){
for(int i = 0; i < n; i++) fa[i] = i;
}

void Kruscal(){
priority_queue<node> pq;
for(int i = 0; i < n; i++)
for(int j = i+1; j < n; j++)
pq.push((node){i, j, Dis(p[i], p[j])});
init();
double ret = 0;
while(!pq.empty()){
node no = pq.top(); pq.pop();
if(Union(no.u, no.v)) ret += no.dis;
}
printf("%.2f\n", ret);
}

int main()
{
int T;
scanf("%d", &T);
while(T--){