結果

問題 No.807 umg tours
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-13 20:58:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,082 ms / 4,000 ms
コード長 942 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 179,528 KB
最終ジャッジ日時 2023-08-15 12:40:05
合計ジャッジ時間 29,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,372 KB
testcase_01 AC 18 ms
8,440 KB
testcase_02 AC 20 ms
8,588 KB
testcase_03 AC 20 ms
8,536 KB
testcase_04 AC 18 ms
8,464 KB
testcase_05 AC 19 ms
8,436 KB
testcase_06 AC 21 ms
8,616 KB
testcase_07 AC 20 ms
8,676 KB
testcase_08 AC 16 ms
8,016 KB
testcase_09 AC 17 ms
8,308 KB
testcase_10 AC 17 ms
8,284 KB
testcase_11 AC 1,870 ms
133,552 KB
testcase_12 AC 1,626 ms
103,344 KB
testcase_13 AC 2,278 ms
142,832 KB
testcase_14 AC 909 ms
67,440 KB
testcase_15 AC 653 ms
54,916 KB
testcase_16 AC 2,392 ms
150,116 KB
testcase_17 AC 3,029 ms
173,976 KB
testcase_18 AC 2,973 ms
172,312 KB
testcase_19 AC 2,798 ms
168,792 KB
testcase_20 AC 1,269 ms
95,696 KB
testcase_21 AC 1,314 ms
99,224 KB
testcase_22 AC 521 ms
47,624 KB
testcase_23 AC 404 ms
39,228 KB
testcase_24 AC 1,439 ms
134,292 KB
testcase_25 AC 3,082 ms
179,528 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