結果

問題 No.807 umg tours
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-13 20:54:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 874 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 11,992 KB
実行使用メモリ 186,052 KB
最終ジャッジ日時 2023-10-21 19:48:43
合計ジャッジ時間 40,003 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,412 KB
testcase_01 AC 34 ms
10,440 KB
testcase_02 AC 36 ms
10,624 KB
testcase_03 AC 34 ms
10,576 KB
testcase_04 AC 32 ms
10,396 KB
testcase_05 AC 33 ms
10,448 KB
testcase_06 AC 37 ms
10,704 KB
testcase_07 AC 35 ms
10,544 KB
testcase_08 AC 31 ms
10,268 KB
testcase_09 AC 32 ms
10,308 KB
testcase_10 AC 31 ms
10,332 KB
testcase_11 AC 3,138 ms
151,808 KB
testcase_12 AC 2,059 ms
108,552 KB
testcase_13 AC 3,113 ms
151,516 KB
testcase_14 AC 1,176 ms
71,316 KB
testcase_15 AC 852 ms
57,872 KB
testcase_16 AC 3,312 ms
157,968 KB
testcase_17 AC 3,951 ms
183,332 KB
testcase_18 AC 3,899 ms
181,284 KB
testcase_19 AC 3,728 ms
176,408 KB
testcase_20 AC 1,425 ms
97,676 KB
testcase_21 AC 1,486 ms
101,104 KB
testcase_22 AC 588 ms
49,512 KB
testcase_23 AC 455 ms
41,164 KB
testcase_24 AC 1,728 ms
140,792 KB
testcase_25 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

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

    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]:
            if minDist[to] > dist + cost:
                heappush(que, (dist + cost, to))

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

sol()
0