# [JSOJ2010]部落划分

4 2
0 0
0 1
1 1
1 0

1.00

9 3
2 2
2 3
3 2
3 3
3 5
3 6
4 6
6 2
6 3

2.00

## Code

#include<bits/stdc++.h>

using namespace std;
const int maxn=1010;

int F[maxn],siz[maxn],cnt;
double x[maxn],y[maxn];

struct Edge{
double x,y;
double weight;
}Ed[maxn*maxn];
bool cmp(Edge a,Edge b){return a.weight<b.weight;}

double dis(int a,int b){
return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
}

void Init_Set(){
for(int i=0;i<maxn;i++){
siz[i]=0; F[i]=i;
}
}

int Find(int x){
if(F[x]==x) return x;
return F[x]=Find(F[x]);
}

void Union_Set(int x,int y){
if((x=Find(x))==(y=Find(y))) return;
if(siz[x]<siz[y]) F[x]=y;
else if(siz[x]>siz[y]) F[y]=x;
else{
F[x]=y; siz[y]++;
}
}

int main(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
cnt=0;
for(int i=1;i<n;i++){
for(int j=i+1;j<=n;j++){
Ed[++cnt].weight=dis(i,j);
Ed[cnt].x=i;
Ed[cnt].y=j;
}
}

sort(Ed+1,Ed+cnt+1,cmp);
int t=n;
double ans=0;
Init_Set();
for(int i=1;i<=cnt;i++){
if(t<=k){
for(int j=i;j<=cnt;j++){
if(Find(Ed[j].x)!=Find(Ed[j].y)){
ans=Ed[j].weight;
break;
}
}
break;
}
if(Find(Ed[i].x)!=Find(Ed[i].y)){
Union_Set(Ed[i].x,Ed[i].y);
t--;
}
}
printf("%.2f\n",ans);
return 0;
}


12-30 1296

12-18 1356
09-08 31
01-14 26
08-20 1059
03-13 813
01-04 9207
06-27 8727
11-15 9239
11-22 1612
07-21 1096
06-01 1万+
05-19 2770
05-12 3601