結果

問題 No.807 umg tours
ユーザー irumo8202irumo8202
提出日時 2022-01-23 09:33:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,252 ms / 4,000 ms
コード長 902 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 174,500 KB
最終ジャッジ日時 2024-05-06 20:10:41
合計ジャッジ時間 15,143 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
63,028 KB
testcase_01 AC 46 ms
62,708 KB
testcase_02 AC 51 ms
66,032 KB
testcase_03 AC 55 ms
66,344 KB
testcase_04 AC 44 ms
62,512 KB
testcase_05 AC 46 ms
62,600 KB
testcase_06 AC 53 ms
65,652 KB
testcase_07 AC 51 ms
63,348 KB
testcase_08 AC 38 ms
53,472 KB
testcase_09 AC 36 ms
54,600 KB
testcase_10 AC 38 ms
54,860 KB
testcase_11 AC 698 ms
138,464 KB
testcase_12 AC 748 ms
130,036 KB
testcase_13 AC 994 ms
149,672 KB
testcase_14 AC 489 ms
107,892 KB
testcase_15 AC 408 ms
101,304 KB
testcase_16 AC 981 ms
153,144 KB
testcase_17 AC 1,244 ms
169,832 KB
testcase_18 AC 1,228 ms
169,728 KB
testcase_19 AC 1,162 ms
166,104 KB
testcase_20 AC 624 ms
124,328 KB
testcase_21 AC 636 ms
126,392 KB
testcase_22 AC 300 ms
97,508 KB
testcase_23 AC 267 ms
92,948 KB
testcase_24 AC 556 ms
157,376 KB
testcase_25 AC 1,252 ms
174,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

INF = 1 << 60


def dijkstra(s, edge):
    n = len(edge)
    dist = [INF] * n
    dist[s] = 0
    hq = []
    heappush(hq, (dist[s], s))

    while hq:
        dist_v, v = heappop(hq)
        if dist_v > dist[v]:
            continue
        for cost, nx in edge[v]:
            if dist[nx] > dist[v] + cost:
                dist[nx] = dist[v] + cost
                heappush(hq, (dist[nx], nx))
    return dist


N, M = map(int, input().split())
G = [[] for _ in range(2 * N)]

for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append((c, b))
    G[b].append((c, a))
    G[a].append((0, b + N))
    G[b].append((0, a + N))
    G[a + N].append((c, b + N))
    G[b + N].append((c, a + N))

for i in range(N):
    G[i].append((0, i + N))

dist = dijkstra(0, G)

for i in range(N):
    ans = dist[i] + dist[i + N]
    print(ans)
0