0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 01:38:48 +00:00
OI-codes/Luogu/P1744/P1744.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

2021-07-20 16:11:31 +00:00
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, s, t;
vector<pair<int, int>> d(1);
2021-07-20 16:12:05 +00:00
vector<pair<int, double>> g[105];
double dist[105];
bool st[105];
2021-07-20 16:11:31 +00:00
double dis(pair<int, int> a, pair<int, int> b) {
return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2));
}
2021-07-20 16:12:05 +00:00
void dijkstra() {
for (int i = 1; i <= n; i++) {
dist[i] = 1e9;
}
dist[s] = 0.00;
priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
q.push(make_pair(0.00, s));
while (!q.empty()) {
auto t = q.top();
q.pop();
if (st[t.second]) continue;
for (auto i : g[t.second]) {
if (dist[i.first] > t.first + i.second) {
dist[i.first] = t.first + i.second;
q.push(make_pair(dist[i.first], i.first));
}
}
st[t.second] = true;
}
}
2021-07-20 16:11:31 +00:00
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
d.push_back(make_pair(x, y));
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
2021-07-20 16:12:05 +00:00
g[x].push_back(make_pair(y, dis(d[x], d[y])));
g[y].push_back(make_pair(x, dis(d[x], d[y])));
2021-07-20 16:11:31 +00:00
}
cin >> s >> t;
2021-07-20 16:12:05 +00:00
dijkstra();
cout << fixed << setprecision(2) << dist[t] << endl;
2021-07-20 16:11:31 +00:00
return 0;
2021-07-20 16:12:05 +00:00
}