uva 10369 By ACReaper

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn_v = 1024;
const int maxn_e = maxn_v * (maxn_v - 1) / 2;
int u[maxn_e];
int v[maxn_e];
double w[maxn_e];
int r[maxn_e];
int fa[maxn_v];
struct pos{
	double x,y;
};
pos A[maxn_v];
int cmp(const int i,const int j){
	return w[i] < w[j];
}
int find(int x){
	return x == fa[x]?x:(fa[x] = find(fa[x]));
}
int main(){
	int n,s,p;
	while(scanf("%d",&n)!= EOF){
		for(int tc = 1; tc <= n;tc++){
			scanf("%d%d",&s,&p);
			for(int i = 1; i <= p; i++){
				scanf("%lf%lf",&A[i].x,&A[i].y);
			}
			int k = 1;
			for(int i = 1; i <= p; i++){
				for(int j = i + 1; j <= p ; j++){
					double d1 = A[i].x - A[j].x;
					double d2 = A[i].y - A[j].y;
					u[k] = i,v[k] = j,w[k++]= sqrt(d1*d1 + d2*d2);
				}
			}
			k--;
			for(int j = 1; j <= maxn_v; j++){
				fa[j] = j;
			}
			for(int j = 1; j <= maxn_e; j++){
				r[j] = j;
			}
			sort(r + 1,r + 1 + k,cmp);
			int count = 0;
			double min_d = 0.0;	
			for(int j = 1; j <= k; j++){
				int e =r[j]; 
				int x = find(u[e]);
				int y = find(v[e]);
				if(x != y){
					fa[x] = y;
					count++;
					if(count == p - s){//s个卫星频道,所以只有s - 1个卫星,而一个卫星可以建立一条边,所以是s - 1条边 
						min_d = w[e];
				
					}	
				}
			}
			printf("%d %.2lf\n",count,min_d);
		}
	}	
}
 By ACReaper
2013 05 09


posted @ 2013-05-09 01:10  算法黑魔王  阅读(130)  评论(0编辑  收藏  举报