思路:先按题目给的那两个点连一条边,然后剩下的求kruskal就好了
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define INF 0x3f3f3f3f
#define esp 1e-9
typedef long long LL;
using namespace std;
int n;
struct edge
{
int i,j;
double w;
bool operator<(const edge&a)const
{
return w<a.w;
}
}a[100*100];
int x[100],y[100];
double dis(int i,int j)
{
return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
int nick,apple,pa[100];
int find(int x) {
return x==pa[x]?x:pa[x]=find(pa[x]);
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n)==1&&n)
{
scanf("%d%d",&nick,&apple);
for(int i=1;i<=n;i++) scanf("%d%d",x+i,y+i);
int m=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[m++]=edge{ i,j,dis(i,j) };
sort(a,a+m);
double ans=dis(apple,nick);
for(int i=1;i<=n;i++) pa[i]=i;
pa[nick]=apple;
for(int i=2,j=0;i<n&&j<m;j++)
{
int x=find(a[j].i);
int y=find(a[j].j);
if(x!=y)
{
ans+=a[j].w;
pa[x]=y;
}
}
printf("%.2lf\n",ans);
}
return 0;
}