1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| #include <iostream> #include <vector> #include <cstring> #include <queue> #include <cmath> #include <limits>
using namespace std; #define int long long typedef pair<int, int> PII; vector<PII> v; int sx, sy, tx, ty; int v1, v2; const int N = 1e6 + 10, M = 2 * N; int head[M], to[M], ne[M], idx; double w[M], dist[M]; bool st[M]; int n; typedef pair<double, int> PII2; priority_queue<PII2, vector<PII2>, greater<PII2>> h; double inf = std::numeric_limits<double>::infinity(); void add(int x, int y, double t) { to[idx] = y, ne[idx] = head[x], w[idx] = t, head[x] = idx++; } double get_dist(PII a, PII b) { int x1 = a.first, y1 = a.second; int x2 = b.first, y2 = b.second; double dist = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); return dist; } double Dijksta(int s) { for (int i = 0; i <= n + 1; i++) dist[i] = inf; dist[s] = 0; h.push({0, s}); while (h.size()) { PII q = h.top(); int a = q.second, b = q.first; h.pop(); if (st[a]) continue; st[a] = true; for (int i = head[a]; i != -1; i = ne[i]) { int j = to[i]; if (dist[j] - (dist[a] + w[i]) > 1e-8) { dist[j] = dist[a] + w[i]; h.push({ dist[j], j }); } } } return dist[n + 1]; } signed main() { std::ios::sync_with_stdio(0); std::cin.tie(0); memset(head, -1, sizeof head); cin >> n; v.push_back({ 0, 0 }); for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; v.push_back({ x, y }); } cin >> sx >> sy >> tx >> ty; cin >> v1 >> v2; for(int i = 1; i <= n - 1; i++) for (int j = i + 1; j <= n; j++) { double dis = get_dist(v[i], v[j]); if (dis > 3.0 * v2) { add(i, j, 3.0 + (dis - 3.0 * v2) / v1); add(j, i, 3.0 + (dis - 3.0 * v2) / v1); } else { add(i, j, dis / v2); add(j, i, dis / v2); } } for (int i = 1; i <= n; i++) { add(0, i, get_dist({ sx, sy }, v[i]) / v1); add(i, 0, get_dist({ sx, sy }, v[i]) / v1); double dist = get_dist({ tx, ty }, v[i]); if (dist > v2 * 3.0) { add(i, n + 1, 3.0 + (dist - v2 * 3.0) / v1); add(n + 1, i, 3.0 + (dist - v2 * 3.0) / v1); } else { add(i, n + 1, dist / v2); add(n + 1, i, dist / v2); } } double dist = get_dist({ sx,sy }, { tx,ty }); add(0, n + 1, dist / v1); add(n + 1, 0, dist / v1); double ans = Dijksta(0); printf("%.12lf", ans); return 0; }
|