結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー merom686merom686
提出日時 2020-05-29 22:04:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,861 bytes
コンパイル時間 1,126 ms
コンパイル使用メモリ 111,540 KB
実行使用メモリ 16,544 KB
最終ジャッジ日時 2024-04-23 22:33:31
合計ジャッジ時間 6,946 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 107 ms
9,088 KB
testcase_03 AC 176 ms
14,836 KB
testcase_04 AC 187 ms
14,960 KB
testcase_05 AC 145 ms
14,960 KB
testcase_06 AC 146 ms
14,880 KB
testcase_07 AC 53 ms
6,944 KB
testcase_08 AC 206 ms
14,252 KB
testcase_09 AC 18 ms
6,944 KB
testcase_10 AC 91 ms
8,120 KB
testcase_11 AC 60 ms
6,944 KB
testcase_12 AC 44 ms
6,944 KB
testcase_13 AC 121 ms
10,992 KB
testcase_14 AC 132 ms
12,780 KB
testcase_15 AC 159 ms
13,672 KB
testcase_16 AC 79 ms
9,060 KB
testcase_17 AC 181 ms
14,800 KB
testcase_18 AC 62 ms
7,388 KB
testcase_19 AC 158 ms
13,916 KB
testcase_20 AC 46 ms
6,944 KB
testcase_21 AC 76 ms
8,412 KB
testcase_22 AC 148 ms
13,168 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 38 ms
6,944 KB
testcase_26 AC 83 ms
8,812 KB
testcase_27 AC 90 ms
9,536 KB
testcase_28 AC 144 ms
13,832 KB
testcase_29 AC 23 ms
6,940 KB
testcase_30 AC 148 ms
13,960 KB
testcase_31 AC 110 ms
11,432 KB
testcase_32 AC 67 ms
7,936 KB
testcase_33 AC 155 ms
16,544 KB
testcase_34 AC 62 ms
7,536 KB
testcase_35 AC 150 ms
14,208 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 3 ms
6,940 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 238 ms
14,216 KB
testcase_42 AC 68 ms
6,944 KB
testcase_43 AC 114 ms
9,268 KB
testcase_44 AC 39 ms
6,944 KB
testcase_45 AC 121 ms
9,232 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    static constexpr double INF = 1e+100;
    struct VertexQ {
        bool operator<(const VertexQ &o) const {
            return c > o.c; // 逆
        }
        int i;
        double c;
    };
    struct Vertex { int n; double c; };
    struct Edge { int i, n; double c; };
    Graph(int n, int m) : v(n, { -1, INF }), e(m), n(n), m(0) {}
    void add_edge(int i, int j, double c) {
        e[m] = { j, v[i].n, c };
        v[i].n = m;
        m++;
    }
    void dijkstra(int i, int j) {
        for (int i = 0; i < n; i++) v[i].c = INF;
        priority_queue<VertexQ> q;
        q.push({ i, v[i].c = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.i == j) break;
            if (p.c > v[p.i].c) continue;
            for (int j = v[p.i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                double c = p.c + o.c;
                if (c < v[o.i].c) q.push({ o.i, v[o.i].c = c });
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

int main() {
    int n, m;
    cin >> n >> m;
    
    Graph g(n, m * 2);

    int x, y;
    cin >> x >> y;
    x--; y--;

    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        p[i] = { x, y };
    }

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        double c = hypot(p[a].first - p[b].first, p[a].second - p[b].second);
        g.add_edge(a, b, c);
        g.add_edge(b, a, c);
    }

    g.dijkstra(x, y);

    cout << fixed << setprecision(9) << g.v[y].c << '\n';

    return 0;
}
0