結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー simkarensimkaren
提出日時 2020-05-30 15:14:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 1,550 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 191,660 KB
実行使用メモリ 31,328 KB
最終ジャッジ日時 2024-04-25 07:23:07
合計ジャッジ時間 10,602 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 164 ms
17,024 KB
testcase_03 AC 246 ms
31,328 KB
testcase_04 AC 239 ms
30,820 KB
testcase_05 AC 187 ms
30,820 KB
testcase_06 AC 207 ms
30,944 KB
testcase_07 AC 58 ms
10,240 KB
testcase_08 AC 226 ms
28,672 KB
testcase_09 AC 20 ms
5,632 KB
testcase_10 AC 100 ms
14,592 KB
testcase_11 AC 66 ms
11,136 KB
testcase_12 AC 47 ms
10,752 KB
testcase_13 AC 163 ms
20,984 KB
testcase_14 AC 193 ms
24,364 KB
testcase_15 AC 228 ms
26,596 KB
testcase_16 AC 110 ms
17,160 KB
testcase_17 AC 251 ms
28,616 KB
testcase_18 AC 79 ms
13,532 KB
testcase_19 AC 227 ms
27,140 KB
testcase_20 AC 58 ms
9,804 KB
testcase_21 AC 92 ms
16,488 KB
testcase_22 AC 216 ms
25,548 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 45 ms
10,624 KB
testcase_26 AC 120 ms
17,780 KB
testcase_27 AC 123 ms
17,780 KB
testcase_28 AC 215 ms
27,172 KB
testcase_29 AC 26 ms
7,936 KB
testcase_30 AC 228 ms
29,320 KB
testcase_31 AC 154 ms
23,036 KB
testcase_32 AC 95 ms
15,440 KB
testcase_33 AC 220 ms
29,844 KB
testcase_34 AC 78 ms
13,184 KB
testcase_35 AC 232 ms
29,604 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 4 ms
5,376 KB
testcase_38 AC 3 ms
5,376 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 352 ms
29,952 KB
testcase_42 AC 90 ms
11,520 KB
testcase_43 AC 166 ms
17,536 KB
testcase_44 AC 53 ms
8,704 KB
testcase_45 AC 157 ms
17,024 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

template<typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G){
    const int n = G.size();
    vector<T> d(n, numeric_limits<T>::max());
    vector<int> b(n, -1);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
    d[s] = 0;
    q.emplace(d[s], s);
    while (!q.empty()){
        pair<T, int> p = q.top();
        q.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto& e : G[v]){
            int u = e.first;
            T c = e.second;
            if (d[u] > d[v] + c){
                d[u] = d[v] + c;
                b[u] = v;
                q.emplace(d[u], u);
            }
        }
    }
    return d;
}

int N, M;
int X, Y;
vector<pair<int, int>> pq;

void input(void){
    cin >> N >> M;
    pq.resize(N);
    cin >> X >> Y;
    --X, --Y;
    for (int i = 0; i < N; ++i)
        cin >> pq[i].first >> pq[i].second;
}

ld dist(int a, int b){
    int dx = pq[a].first - pq[b].first;
    int dy = pq[a].second - pq[b].second;
    return sqrtl(dx * dx + dy * dy);
}

int main(void){
    input();
    vector<vector<pair<int, ld>>> g(N);
    for (int i = 0; i < M; ++i){
        int P, Q; cin >> P >> Q;
        --P, --Q;
        ld cost = dist(P, Q);
        g[P].emplace_back(Q, cost);
        g[Q].emplace_back(P, cost);
    }
    auto d = dijkstra(X, g);
    cout << setprecision(15) << d[Y] << endl;
    return 0;
}
0