結果

問題 No.1065 電柱 / Pole (Easy)
コンテスト
ユーザー kokatsu
提出日時 2022-12-14 22:53:17
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 877 ms / 2,000 ms
コード長 1,027 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,101 ms
コンパイル使用メモリ 211,932 KB
実行使用メモリ 22,088 KB
最終ジャッジ日時 2026-03-06 22:29:32
合計ジャッジ時間 19,549 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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