what happened?
```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int sum=0;
int f[2001];
struct point
{
int x,y;
long long z;
};
point a[4000001];
struct edge
{
int x,y;
};
edge v[4000001];
int find(int x)
{
if(f[x]!=x)
f[x]=find(f[x]);
return f[x];
}
void unio(int x,int y)
{
x=find(x);
y=find(y);
if(x!=y)
f[x]=y;
}
int cmp(const point &a,const point &b)
{
if(a.z<b.z)
return 1;
else
return 0;
}
int n,m,c,k;
int main()
{
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++)
scanf("%d%d",&v[i].x,&v[i].y);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
m++;
a[m].x=i;
a[m].y=j;
a[m].z=pow(v[i].x-v[j].x,2)+pow(v[i].y-v[j].y,2);
if(a[m].z<c)
a[m].z=100000000;
}
for(int i=1;i<=n;i++)
f[i]=i;
sort(a+1,a+m+1,cmp);
for(int i=1;i<=m;i++)
{
if(find(a[i].x)!=find(a[i].y))
{
sum+=a[i].z;
k++;
unio(a[i].x,a[i].y);
}
if(k==n-1)
break;
}
if(m>1)
cout<<"-1";
else
cout<<sum;
return 0;
}
```
最后一个点-1过了;但其他九个点全错;
```cpp
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int sum=0;
int f[2001];
struct point
{
int x,y;
long long z;
};
point a[4000001];
struct edge
{
int x,y;
};
edge v[4000001];
int find(int x)
{
if(f[x]!=x)
f[x]=find(f[x]);
return f[x];
}
void unio(int x,int y)
{
x=find(x);
y=find(y);
if(x!=y)
f[x]=y;
}
int cmp(const point &a,const point &b)
{
if(a.z<b.z)
return 1;
else
return 0;
}
int n,m,c,k;
int main()
{
scanf("%d%d",&n,&c);
for(int i=1;i<=n;i++)
scanf("%d%d",&v[i].x,&v[i].y);
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
m++;
a[m].x=i;
a[m].y=j;
a[m].z=pow(v[i].x-v[j].x,2)+pow(v[i].y-v[j].y,2);
if(a[m].z<c)
a[m].z=100000000;
}
for(int i=1;i<=n;i++)
f[i]=i;
sort(a+1,a+m+1,cmp);
for(int i=1;i<=m;i++)
{
if(find(a[i].x)!=find(a[i].y))
{
sum+=a[i].z;
k++;
unio(a[i].x,a[i].y);
}
if(k==n-1)
break;
}
cout<<sum;
return 0;
}
```
前九个点过了,最后一个点过不了;
什么情况?
by LYang @ 2017-04-22 19:33:40
@[斗罗](/space/show?uid=35364)
题目中有说输出-1的,不能生成最小生成树,则输出-1,题目没有翻译,我也错了一次,以后还是要认真读题。
! ![](https://cdn.luogu.com.cn/upload/pic/6410.png) (https://www.luogu.org/app/upload)
by Drifterming @ 2017-07-19 17:06:13
![](https://cdn.luogu.com.cn/upload/pic/6410.png) (https://www.luogu.org/app/upload)
by Drifterming @ 2017-07-19 17:07:20
为什么我不能上传图片?
by Drifterming @ 2017-07-19 17:08:01
@[明豆豆](/space/show?uid=39886) pic不是这么用的233333你是用的![luogu]那个代码然后加上pic的吗233
by 蔚兰飞雪 @ 2017-07-19 17:11:22
@[明豆豆](/space/show?uid=39886)
```cpp
![](https://cdn.luogu.com.cn/upload/pic/6410.png)
```
by zhengrunzhe @ 2017-07-19 17:29:26
@[YLFX](/space/show?uid=38740) 那应该往哪儿加那个[pic=xxx]呢?我看到它给出了[]这个框,然后往里面写了pic=xxx,然后就成了我第一次发的那样,我把前面那个!删了,就成了一个链接。。
by Drifterming @ 2017-07-19 17:40:17
@[明豆豆](/space/show?uid=39886) 哦 知道了,谢了
by LYang @ 2017-07-19 18:03:05
@[明豆豆](/space/show?uid=39886) 格式为【luogu】(123123123123123123)的为网络传送门连接,里面的luogu可以改比如说[帮助传送门](https://www.luogu.org/wiki/show?name=%E5%B8%AE%E5%8A%A9%EF%BC%9Amarkdown),里面就是“帮助传送门”这几个字,
然后!【luogu】()为网络图片,括号里放该图片的连接,一般可以在网页右键某图片后,复制图片链接 然后使用
#【pic=xxx】是luogu的图床,都是dalao上传的图片编号,你也可以自己上传然后luogu会告诉你这个图床的编号然后使用就行了
上传在“题目搜索”左边的应用栏里
这里比如我上传的我自己的头像编号是6392,我就
#可以【PIC=6392】
(代码输入就是小写pic和框框这个你懂)
就这样
![](https://cdn.luogu.com.cn/upload/pic/6392.png)
by 蔚兰飞雪 @ 2017-07-20 14:32:20
@[YLFX](/space/show?uid=38740) 那这个[pic=xxx]的框框往哪放?
by Drifterming @ 2017-07-20 14:54:59