提交时间:2022-06-11 16:55:13

运行 ID: 41297

#include <iostream> #include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> struct node { int x,y; }point[110]; int i,j,m,n; using namespace std; double map[601][601]; int Max=10000000; int fld(int n){ int i,j,k; for(k=1;k<=n;k++){ for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(map[i][j]>map[i][k]+map[k][j]) map[i][j]=map[i][k]+map[k][j]; } } }} double di(int aa,int bb){ int x=point[aa].x-point[bb].x; int y=point[aa].y-point[bb].y; return sqrt(x*x+y*y); } int main(){ cin>>n; for(i=1;i<=n;i++) { cin>>point[i].x>>point[i].y; } cin>>m; int aa,bb; for(i=1;i<=n;i++){ for(j=1;j<=n;j++) { map[i][j]=map[j][i]=Max; } map[i][i]=0; } for(i=1;i<=m;i++){ cin>>aa>>bb; if(map[aa][bb]>di(aa,bb)) map[aa][bb]=di(aa,bb); map[bb][aa]=di(aa,bb); } int qq,ww; fld(n); cin>>qq>>ww; printf("%.2lf\n",map[qq][ww]); }