You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include <cstdio>
|
|
#include <cmath>
|
|
#include <cstring>
|
|
#include <algorithm>
|
|
#include <queue>
|
|
using namespace std;
|
|
struct edge
|
|
{
|
|
int f,t;
|
|
double l;
|
|
} e[2501];
|
|
bool operator<(const edge&lhs,const edge&rhs)
|
|
{
|
|
return lhs.l>rhs.l;
|
|
}
|
|
int X[53],Y[53];
|
|
int f[53];
|
|
int fa(int x){return f[x]==x?x:f[x]=fa(f[x]);}
|
|
int main()
|
|
{
|
|
int n,p,q;
|
|
while(scanf("%d",&n),n)
|
|
{
|
|
priority_queue<edge> Q;
|
|
for(int i=0;i<53;i++) f[i]=i;
|
|
scanf("%d%d",&p,&q),p--,q--;
|
|
for(int i=0; i<n; i++)
|
|
scanf("%d%d",X+i,Y+i);
|
|
for(int i=0; i<n; i++)
|
|
for(int j=0; j<n; j++)
|
|
e[i*n+j]= {i,j,sqrt((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]))};
|
|
double ans=e[p*n+q].l;
|
|
f[fa(p)]=fa(q);
|
|
for(int i=0; i<n; i++)
|
|
for(int j=0; j<n; j++)
|
|
Q.push(e[i*n+j]);
|
|
int cnt=n-1;
|
|
while (!Q.empty())
|
|
{
|
|
edge e = Q.top();
|
|
Q.pop();
|
|
if (fa(e.f) != fa(e.t))
|
|
{
|
|
f[fa(e.f)] = fa(e.t);
|
|
ans += e.l;
|
|
cnt--;
|
|
if (cnt == 1) break;
|
|
}
|
|
}
|
|
printf("%.2lf\n", ans);
|
|
}
|
|
return 0;
|
|
}
|