把符合条件的边存下来
然后最小生成树
type
jl=record
x,y,z:longint;
end;
var
a:array[1..1999000]of jl;
p,r,b,d:array[1..2000]of longint;
n,m,i,c,t,s,j,k:longint;
procedure js(l,r:longint);
var
t:jl;
m,i,j:longint;
begin
i:=l;j:=r;m:=a[l+1].z;
repeat
while a[i].z<m do inc(i);
while a[j].z>m do dec(j);
if i<=j then
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
inc(i);dec(j);
end;
until i>j;
if l<j then js(l,j);
if i<r then js(i,r);
end;
function find(x:longint):longint;
begin
if p[x]<>x then p[x]:=find(p[x]);
find:=p[x];p[x]:=find;
end;
procedure hb(x,y:longint);
begin
x:=find(x);y:=find(y);
if r[x]>r[y]then
begin
t:=x;x:=y;y:=t;
end;
if r[x]=r[y]then inc(r[x]);
p[x]:=y;
end;
begin
read(n,c);
for i:=1 to n do
begin
p[i]:=i;
read(b[i],d[i]);
for j:=1 to i-1 do if sqr(abs(b[i]-b[j]))+sqr(abs(d[i]-d[j]))>=c then
begin
inc(m);
a[m].x:=i;
a[m].y:=j;
a[m].z:=sqr(abs(b[i]-b[j]))+sqr(abs(d[i]-d[j]));
end;
end;
js(1,m);
i:=0;
repeat
inc(i);
if i>m then begin write(-1);halt;end;
with a[i]do if find(x)<>find(y)then
begin
hb(x,y);
inc(k);
inc(s,z);
end;
until k=n-1;
write(s);
end.