結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー kokatsukokatsu
提出日時 2022-12-14 22:53:17
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 497 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 4,253 ms
コンパイル使用メモリ 228,204 KB
実行使用メモリ 21,048 KB
最終ジャッジ日時 2023-09-04 19:22:59
合計ジャッジ時間 18,855 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 254 ms
13,116 KB
testcase_03 AC 375 ms
20,856 KB
testcase_04 AC 371 ms
19,768 KB
testcase_05 AC 293 ms
18,712 KB
testcase_06 AC 294 ms
21,048 KB
testcase_07 AC 78 ms
7,720 KB
testcase_08 AC 295 ms
20,612 KB
testcase_09 AC 27 ms
5,000 KB
testcase_10 AC 131 ms
10,628 KB
testcase_11 AC 89 ms
8,356 KB
testcase_12 AC 73 ms
6,720 KB
testcase_13 AC 277 ms
13,192 KB
testcase_14 AC 325 ms
17,632 KB
testcase_15 AC 379 ms
20,596 KB
testcase_16 AC 182 ms
10,184 KB
testcase_17 AC 409 ms
20,264 KB
testcase_18 AC 129 ms
9,176 KB
testcase_19 AC 382 ms
20,560 KB
testcase_20 AC 100 ms
8,616 KB
testcase_21 AC 156 ms
8,992 KB
testcase_22 AC 359 ms
17,880 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 66 ms
6,468 KB
testcase_26 AC 198 ms
13,196 KB
testcase_27 AC 204 ms
12,068 KB
testcase_28 AC 352 ms
15,332 KB
testcase_29 AC 45 ms
5,116 KB
testcase_30 AC 370 ms
19,292 KB
testcase_31 AC 258 ms
14,740 KB
testcase_32 AC 162 ms
12,676 KB
testcase_33 AC 379 ms
20,608 KB
testcase_34 AC 135 ms
10,480 KB
testcase_35 AC 371 ms
18,640 KB
testcase_36 AC 4 ms
4,380 KB
testcase_37 AC 6 ms
4,380 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 6 ms
4,384 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 497 ms
20,176 KB
testcase_42 AC 140 ms
10,384 KB
testcase_43 AC 256 ms
14,284 KB
testcase_44 AC 86 ms
7,560 KB
testcase_45 AC 251 ms
13,180 KB
testcase_46 AC 1 ms
4,384 KB
testcase_47 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct Pole {
    int to;
    real dist;
}

void main() {
    int N, M, X, Y;
    readf("%d %d\n%d %d\n", N, M, X, Y);

    --X, --Y;

    auto p = new real[](N), q = new real[](N);
    foreach (i; 0 .. N) readf("%f %f\n", p[i], q[i]);

    auto poles = new int[][](N);
    foreach (_; 0 .. M) {
        int P, Q;
        readf("%d %d\n", P, Q);

        --P, --Q;
        poles[P] ~= Q, poles[Q] ~= P;
    }

    auto dists = new real[](N);
    dists[] = real.max;
    dists[X] = 0.0;

    auto heap = new BinaryHeap!(Array!Pole, "a.dist > b.dist")();
    heap.insert(Pole(X, 0.0));
    while (!heap.empty) {
        auto f = heap.front;
        heap.popFront;

        if (f.dist > dists[f.to]) continue;

        foreach (pole; poles[f.to]) {
            real d = f.dist + hypot(p[f.to]-p[pole], q[f.to]-q[pole]);
            if (d < dists[pole]) {
                dists[pole] = d;
                heap.insert(Pole(pole, d));
            }
        }
    }

    real res = dists[Y];
    writefln("%.10f", res);
}
0