結果

問題 No.807 umg tours
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-13 20:59:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,303 ms / 4,000 ms
コード長 942 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 167,432 KB
最終ジャッジ日時 2024-05-03 00:07:44
合計ジャッジ時間 14,108 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
60,928 KB
testcase_01 AC 48 ms
63,104 KB
testcase_02 AC 56 ms
66,816 KB
testcase_03 AC 51 ms
63,360 KB
testcase_04 AC 46 ms
60,672 KB
testcase_05 AC 45 ms
61,056 KB
testcase_06 AC 52 ms
64,768 KB
testcase_07 AC 49 ms
62,720 KB
testcase_08 AC 37 ms
52,736 KB
testcase_09 AC 35 ms
52,992 KB
testcase_10 AC 37 ms
53,632 KB
testcase_11 AC 727 ms
137,044 KB
testcase_12 AC 700 ms
125,068 KB
testcase_13 AC 974 ms
144,248 KB
testcase_14 AC 467 ms
105,540 KB
testcase_15 AC 384 ms
99,320 KB
testcase_16 AC 973 ms
147,928 KB
testcase_17 AC 1,244 ms
161,512 KB
testcase_18 AC 1,236 ms
162,008 KB
testcase_19 AC 1,108 ms
158,108 KB
testcase_20 AC 663 ms
123,972 KB
testcase_21 AC 699 ms
127,560 KB
testcase_22 AC 319 ms
97,964 KB
testcase_23 AC 278 ms
93,752 KB
testcase_24 AC 560 ms
150,372 KB
testcase_25 AC 1,303 ms
167,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

def sol():
    N, M = map(int, input().split())
    edges = [[] for _ in range(2 * N)]

    edges[0].append((N, 0))

    for _ in range(M):
        fr, to, cost = map(int, input().split())
        fr -= 1
        to -= 1
        edges[fr].append((to, cost))
        edges[to].append((fr, cost))
        edges[fr + N].append((to + N, cost))
        edges[to + N].append((fr + N, cost))
        edges[fr].append((to + N, 0))
        edges[to].append((fr + N, 0))

    que = [(0, 0)]
    minDist = [float('inf')] * (2 * N)
    while que:
        dist, now = heappop(que)
        if minDist[now] < dist:
            continue
        minDist[now] = dist
        for to, cost in edges[now]:
            d = dist + cost
            if minDist[to] > d:
                heappush(que, (d, to))
                minDist[to] = d

    print(0)
    for i in range(1, N):
        print(minDist[i] + minDist[i + N])

sol()
0