結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー trineutrontrineutron
提出日時 2020-05-29 22:08:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 2,461 ms
コンパイル使用メモリ 207,864 KB
実行使用メモリ 20,912 KB
最終ジャッジ日時 2024-04-23 22:44:53
合計ジャッジ時間 8,613 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 118 ms
12,416 KB
testcase_03 AC 202 ms
20,296 KB
testcase_04 AC 207 ms
20,040 KB
testcase_05 AC 182 ms
20,292 KB
testcase_06 AC 181 ms
20,168 KB
testcase_07 AC 60 ms
7,936 KB
testcase_08 AC 230 ms
20,352 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 101 ms
10,880 KB
testcase_11 AC 69 ms
8,576 KB
testcase_12 AC 43 ms
7,040 KB
testcase_13 AC 130 ms
14,020 KB
testcase_14 AC 143 ms
15,940 KB
testcase_15 AC 175 ms
17,648 KB
testcase_16 AC 88 ms
11,068 KB
testcase_17 AC 204 ms
18,904 KB
testcase_18 AC 68 ms
8,888 KB
testcase_19 AC 186 ms
17,880 KB
testcase_20 AC 51 ms
7,552 KB
testcase_21 AC 85 ms
10,480 KB
testcase_22 AC 164 ms
16,832 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 41 ms
6,784 KB
testcase_26 AC 92 ms
11,680 KB
testcase_27 AC 97 ms
11,752 KB
testcase_28 AC 163 ms
17,292 KB
testcase_29 AC 23 ms
6,016 KB
testcase_30 AC 162 ms
18,560 KB
testcase_31 AC 122 ms
15,184 KB
testcase_32 AC 73 ms
10,348 KB
testcase_33 AC 163 ms
19,344 KB
testcase_34 AC 68 ms
9,120 KB
testcase_35 AC 170 ms
19,144 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 3 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 292 ms
20,912 KB
testcase_42 AC 77 ms
8,960 KB
testcase_43 AC 130 ms
12,928 KB
testcase_44 AC 45 ms
6,940 KB
testcase_45 AC 139 ms
12,672 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    x--; y--;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i) >> b.at(i);
    }
    vector<vector<pair<int, double>>> to(n);
    for (int i = 0; i < m; i++) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        int dx = a.at(p) - a.at(q), dy = b.at(p) - b.at(q);
        to.at(p).emplace_back(q, sqrt(dx * dx + dy * dy));
        to.at(q).emplace_back(p, sqrt(dx * dx + dy * dy));
    }
    vector<double> d(n, 1e9);
    d.at(x) = 0;
    priority_queue<pair<double, int>> que;
    que.emplace(0, x);
    while (!que.empty()) {
        auto t = que.top();
        double d0 = -t.first;
        int v = t.second;
        que.pop();
        if (v == y) break;
        if (d.at(v) < d0) continue;
        for (auto next : to.at(v)) {
            if (d.at(next.first) <= d0 + next.second) continue;
            d.at(next.first) = d0 + next.second;
            que.emplace(-d.at(next.first), next.first);
        }
    }
    cout << setprecision(17) << d.at(y) << endl;
}
0