結果

問題 No.807 umg tours
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-13 20:46:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,866 ms / 4,000 ms
コード長 1,233 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 160,664 KB
最終ジャッジ日時 2023-08-15 12:38:28
合計ジャッジ時間 20,806 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
75,860 KB
testcase_01 AC 90 ms
76,636 KB
testcase_02 AC 122 ms
78,188 KB
testcase_03 AC 122 ms
78,316 KB
testcase_04 AC 89 ms
75,864 KB
testcase_05 AC 93 ms
76,592 KB
testcase_06 AC 127 ms
78,316 KB
testcase_07 AC 113 ms
77,456 KB
testcase_08 AC 68 ms
71,252 KB
testcase_09 AC 72 ms
75,812 KB
testcase_10 AC 76 ms
75,896 KB
testcase_11 AC 1,333 ms
143,580 KB
testcase_12 AC 1,062 ms
124,240 KB
testcase_13 AC 1,408 ms
140,636 KB
testcase_14 AC 755 ms
105,500 KB
testcase_15 AC 576 ms
98,616 KB
testcase_16 AC 1,476 ms
141,588 KB
testcase_17 AC 1,728 ms
158,332 KB
testcase_18 AC 1,834 ms
157,928 KB
testcase_19 AC 1,642 ms
150,732 KB
testcase_20 AC 806 ms
116,892 KB
testcase_21 AC 926 ms
119,808 KB
testcase_22 AC 411 ms
93,528 KB
testcase_23 AC 399 ms
92,328 KB
testcase_24 AC 868 ms
148,232 KB
testcase_25 AC 1,866 ms
160,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

N, M = map(int, input().split())
INF = float('inf')
isOnePath = [False] * N

edges = [[] for _ in range(N)]
for _ in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    edges[A].append((B, C))
    edges[B].append((A, C))

minDist = [[INF] * N for _ in range(2)]
que = [(0, (0, 0))]

while que:
    dist, (now, height) = heappop(que)

    if minDist[height][now] <= dist:
        continue
    minDist[height][now] = dist

    if height == 0:
        for to, cost in edges[now]:
            if minDist[0][to] > dist + cost:
                heappush(que, (dist + cost, (to, 0)))
            if minDist[1][to] > dist:
                heappush(que, (dist, (to, 1)))
    else:
        for to, cost in edges[now]:
            if minDist[1][to] > dist + cost:
                heappush(que, (dist + cost, (to, 1)))

reverseDist = [INF] * N
que = [(0, 0)]
while que:
    dist, now = heappop(que)

    if reverseDist[now] <= dist:
        continue
    reverseDist[now] = dist

    for to, cost in edges[now]:
        if reverseDist[to] > dist + cost:
            heappush(que, (dist + cost, to))

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