結果

問題 No.807 umg tours
ユーザー irumo8202irumo8202
提出日時 2022-01-23 09:33:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,556 ms / 4,000 ms
コード長 902 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 175,232 KB
最終ジャッジ日時 2023-08-19 13:05:37
合計ジャッジ時間 21,062 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
75,420 KB
testcase_01 AC 92 ms
75,560 KB
testcase_02 AC 97 ms
75,668 KB
testcase_03 AC 98 ms
76,220 KB
testcase_04 AC 89 ms
75,692 KB
testcase_05 AC 90 ms
75,912 KB
testcase_06 AC 99 ms
76,096 KB
testcase_07 AC 95 ms
75,580 KB
testcase_08 AC 79 ms
71,476 KB
testcase_09 AC 81 ms
71,348 KB
testcase_10 AC 81 ms
71,216 KB
testcase_11 AC 908 ms
141,256 KB
testcase_12 AC 936 ms
131,788 KB
testcase_13 AC 1,227 ms
151,076 KB
testcase_14 AC 643 ms
110,700 KB
testcase_15 AC 472 ms
103,292 KB
testcase_16 AC 1,216 ms
155,744 KB
testcase_17 AC 1,556 ms
171,000 KB
testcase_18 AC 1,529 ms
169,456 KB
testcase_19 AC 1,430 ms
167,860 KB
testcase_20 AC 760 ms
125,636 KB
testcase_21 AC 760 ms
127,772 KB
testcase_22 AC 406 ms
100,228 KB
testcase_23 AC 352 ms
94,804 KB
testcase_24 AC 676 ms
160,764 KB
testcase_25 AC 1,500 ms
175,232 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