显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cstring>
using namespace std;
double w[101][101];
double dis[101];
double zuobiao[101][3];
bool pd[101]={0};
int team[1001];//spfa;
int main()
{
freopen("short.in","r",stdin);
freopen("short.out","w",stdout);
int n,x,y,m,s,t,tail,head;
int maxxx=99999999;
cin>>n;
for(int i=1;i<=n;i++)
{
dis[i]=maxxx;
cin>>zuobiao[i][1]>>zuobiao[i][2];
}
for(int fz1=1;fz1<=n;fz1++)
{
for(int fz2=1;fz2<=n;fz2++)
w[fz1][fz2]=maxxx;
}
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>x>>y;
w[x][y]=w[y][x]=sqrt(pow(double(zuobiao[x][1]-zuobiao[y][1]),2)+pow(double(zuobiao[x][2]-zuobiao[y][2]),2));
}
cin>>s>>t;
dis[s]=0;
tail=1;
pd[s]=true;
head=0;
team[1]=s;
do
{
head++;
int u=team[head];
pd[u]=false;
for(int ls=1;ls<=n;ls++)
{
if(w[u][ls]<maxxx)
{
if(dis[ls]>dis[u]+w[u][ls])
{
dis[ls]=dis[u]+w[u][ls];
if(!pd[ls])
{
tail++;
team[tail]=ls;
pd[ls]=true;
}
}
}
}
}
while(head<tail);
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<dis[t]<<endl;
return 0;
}