刚学。。。
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;
const int N = 1e3 + 5;
int n, m, start, ende;
double dista[N];
bool isin[N];
struct Node
{
int place;
double qz;
};
struct ZB
{
int x, y;
};
ZB arr[N];
vector<Node> vec[N];
double dist(const ZB& a, const ZB& b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
void add_edge(int a, int b)
{
Node tmp;
tmp.place = b;
tmp.qz = dist(arr[a], arr[b]);
vec[a].push_back(tmp);
}
void Init()
{
for (int i = 0; i < N; i++)
{
dista[i] = 1e15;
}
}
void spfa(int g)
{
queue<int> q;
q.push(g);
isin[g] = true;
while (!q.empty())
{
int temp = q.front();
q.pop();
isin[temp] = false;
for (int i = 0; i < vec[temp].size(); i++)
{
Node as = vec[temp][i];
if (dista[as.place] > dista[temp] + as.qz)
{
dista[as.place] = dista[temp] + as.qz;
if (!isin[as.place])
{
isin[as.place] = true;
q.push(as.place);
}
}
}
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> arr[i].x >> arr[i].y;
}
cin >> m;
for (int i = 1; i <= m; i++)
{
int o, l;
cin >> o >> l;
add_edge(o, l);
add_edge(l, o);
}
cin >> start >> ende;
Init();
spfa(start);
printf("%.2lf", dista[ende]);
return 0;
}