
耐克店 和 苹果店必须相连
Sample Input
4
2 3
0 0
1 0
0 -1
1 -1
0
Sample Output
3.41
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# define LL long long
using namespace std ; const int INF=0x3f3f3f3f;
const int MAXN=;
bool vis[MAXN];
double lowc[MAXN];
int n ;
double cost[MAXN][MAXN] ; struct poin
{
int x ;
int y ;
}p[MAXN]; double Prim()//点是0~n-1
{
double ans=;
memset(vis,false,sizeof(vis));
vis[]=true;
for(int i=;i<n;i++)lowc[i]=cost[][i];
for(int i=;i<n;i++)
{
double minc=INF;
int p=-;
for(int j=;j<n;j++)
if(!vis[j]&&minc>lowc[j])
{
minc=lowc[j];
p=j;
}
if(minc==INF)return -;//原图不连通
ans+=minc;
vis[p]=true;
for(int j=;j<n;j++)
if(!vis[j]&&lowc[j]>cost[p][j])
lowc[j]=cost[p][j];
}
return ans;
} int main()
{ // freopen("in.txt","r",stdin) ;
while(scanf("%d" , &n) != EOF)
{
if (n == )
break ;
int i , j ;
int pp , qq ;
scanf("%d %d" , &pp , &qq) ;
for (i = ; i < n ; i++)
scanf("%d %d" , &p[i].x , &p[i].y) ;
for (i = ; i < n ; i++)
for (j = i+ ; j < n ; j++)
{
double t = sqrt((double)(p[i].x - p[j].x) * (p[i].x - p[j].x) + (p[i].y - p[j].y) * (p[i].y - p[j].y)) ;
cost[i][j] = t ;
cost[j][i] = t ;
}
double k = cost[pp-][qq-] ;
cost[pp-][qq-] = ;
cost[qq-][pp-] = ;
k += Prim() ;
printf("%.2lf\n" , k) ; }
return ;
}