結果

問題 No.807 umg tours
ユーザー nebukuro09nebukuro09
提出日時 2019-03-22 21:39:58
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 667 ms / 4,000 ms
コード長 1,246 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 120,408 KB
実行使用メモリ 45,152 KB
最終ジャッジ日時 2023-09-03 23:52:19
合計ジャッジ時間 8,740 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,500 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 480 ms
40,596 KB
testcase_12 AC 347 ms
26,952 KB
testcase_13 AC 522 ms
37,308 KB
testcase_14 AC 206 ms
19,704 KB
testcase_15 AC 157 ms
14,264 KB
testcase_16 AC 562 ms
42,808 KB
testcase_17 AC 654 ms
44,784 KB
testcase_18 AC 658 ms
44,220 KB
testcase_19 AC 647 ms
43,420 KB
testcase_20 AC 295 ms
25,736 KB
testcase_21 AC 309 ms
25,400 KB
testcase_22 AC 121 ms
13,724 KB
testcase_23 AC 93 ms
12,128 KB
testcase_24 AC 347 ms
29,672 KB
testcase_25 AC 667 ms
45,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new Tuple!(int, long)[][](N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2].to!long);
        G[s[1]-1] ~= tuple(s[0]-1, s[2].to!long);
    }

    auto dist = new long[][](N, 2);
    foreach (i; 0..N) dist[i][] = INF;

    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]");
    pq.insert(tuple(0, 0, 0L));

    while (!pq.empty) {
        auto n = pq.front[0];
        auto x = pq.front[1];
        auto d = pq.front[2];
        pq.removeFront;
        if (dist[n][x] <= d) continue;
        dist[n][x] = d;
        foreach (e; G[n]) {
            auto m = e[0];
            auto nd = d + e[1];
            if (dist[m][x] > nd) pq.insert(tuple(m, x, nd));
            if (x == 0 && dist[m][1] > d) pq.insert(tuple(m, 1, d));
        }
    }

    0.writeln;
    foreach (i; 1..N) {
        writeln(dist[i][0] + dist[i][1]);
    }
}
0