結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー Moon0603Moon0603
提出日時 2020-06-11 16:36:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 1,531 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 211,636 KB
実行使用メモリ 34,276 KB
最終ジャッジ日時 2023-09-06 08:16:12
合計ジャッジ時間 10,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 110 ms
18,936 KB
testcase_03 AC 129 ms
32,516 KB
testcase_04 AC 126 ms
31,392 KB
testcase_05 AC 102 ms
32,052 KB
testcase_06 AC 102 ms
31,524 KB
testcase_07 AC 32 ms
11,172 KB
testcase_08 AC 114 ms
33,664 KB
testcase_09 AC 12 ms
5,628 KB
testcase_10 AC 51 ms
16,928 KB
testcase_11 AC 37 ms
12,292 KB
testcase_12 AC 22 ms
9,920 KB
testcase_13 AC 112 ms
20,852 KB
testcase_14 AC 127 ms
24,308 KB
testcase_15 AC 151 ms
27,232 KB
testcase_16 AC 66 ms
15,468 KB
testcase_17 AC 172 ms
29,560 KB
testcase_18 AC 45 ms
12,272 KB
testcase_19 AC 159 ms
27,900 KB
testcase_20 AC 37 ms
10,156 KB
testcase_21 AC 55 ms
14,564 KB
testcase_22 AC 144 ms
25,860 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 21 ms
9,380 KB
testcase_26 AC 83 ms
17,616 KB
testcase_27 AC 80 ms
17,064 KB
testcase_28 AC 152 ms
26,172 KB
testcase_29 AC 15 ms
7,116 KB
testcase_30 AC 163 ms
28,668 KB
testcase_31 AC 107 ms
22,032 KB
testcase_32 AC 64 ms
15,424 KB
testcase_33 AC 160 ms
29,976 KB
testcase_34 AC 51 ms
12,552 KB
testcase_35 AC 165 ms
29,304 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 272 ms
34,276 KB
testcase_42 AC 61 ms
12,884 KB
testcase_43 AC 121 ms
19,768 KB
testcase_44 AC 35 ms
9,064 KB
testcase_45 AC 116 ms
19,364 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct Edge
{
    int to;
    double cost;
};

template<typename T>
vector<T> dijkstra(const vector<vector<Edge>> g, int start)
{
    int n = (int) g.size();
    using P = pair<T, int>;
    vector<T> dist(n, numeric_limits<T>::max());
    priority_queue<P, vector<P>, greater<P>> pq;
    dist[start] = 0;
    pq.push({dist[start], start});
    while (!pq.empty())
    {
        T expected = pq.top().first;
        int i = pq.top().second;
        pq.pop();
        if (dist[i] != expected)
        {
            continue;
        }
        for (Edge e : g[i])
        {
            int j = e.to;
            T c = e.cost;
            if (dist[j] > dist[i] + c)
            {
                dist[j] = dist[i] + c;
                pq.push({dist[j], j});
            }
        }
    }
    return dist;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i] >> q[i];
    }
    vector<vector<Edge>> g(n);
    for (int i = 0; i < m; ++i)
    {
        int P, Q;
        cin >> P >> Q;
        --P;
        --Q;
        double dist = sqrt((p[P] - p[Q]) * (p[P] - p[Q]) + (q[P] - q[Q]) * (q[P] - q[Q]));
        g[P].push_back({Q, dist});
        g[Q].push_back({P, dist});
    }
    vector<double> dist = dijkstra<double>(g, x);
    cout << fixed << setprecision(17) << dist[y] << '\n';
    return 0;
}
0