結果

問題 No.807 umg tours
ユーザー FromBooskaFromBooska
提出日時 2023-08-31 10:52:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,535 ms / 4,000 ms
コード長 1,393 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 171,072 KB
最終ジャッジ日時 2023-08-31 10:53:01
合計ジャッジ時間 21,620 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
75,860 KB
testcase_01 AC 90 ms
75,660 KB
testcase_02 AC 94 ms
75,816 KB
testcase_03 AC 92 ms
75,784 KB
testcase_04 AC 90 ms
75,768 KB
testcase_05 AC 91 ms
75,560 KB
testcase_06 AC 96 ms
76,296 KB
testcase_07 AC 96 ms
76,276 KB
testcase_08 AC 77 ms
71,260 KB
testcase_09 AC 79 ms
71,332 KB
testcase_10 AC 78 ms
71,264 KB
testcase_11 AC 930 ms
139,148 KB
testcase_12 AC 903 ms
128,564 KB
testcase_13 AC 1,220 ms
148,088 KB
testcase_14 AC 663 ms
108,052 KB
testcase_15 AC 489 ms
100,708 KB
testcase_16 AC 1,271 ms
151,684 KB
testcase_17 AC 1,535 ms
164,688 KB
testcase_18 AC 1,530 ms
166,184 KB
testcase_19 AC 1,414 ms
162,296 KB
testcase_20 AC 731 ms
123,056 KB
testcase_21 AC 774 ms
124,916 KB
testcase_22 AC 390 ms
97,348 KB
testcase_23 AC 340 ms
93,552 KB
testcase_24 AC 679 ms
154,308 KB
testcase_25 AC 1,532 ms
171,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ダイクストラ
# ミラー頂点をN個作る、辺構造も同じ
# ミラーへは有向辺コスト0
# ダイクストラ1回で済ませられるか

N, M = map(int, input().split())
edges = [[] for i in range(N*2+1)]
for i in range(M):
    a, b, c = map(int, input().split())
    # 現世界内
    edges[a].append((b, c))
    edges[b].append((a, c))
    # ミラー世界内
    edges[a+N].append((b+N, c))
    edges[b+N].append((a+N, c))  
    # 現世界からミラー世界に有効辺コスト0
    edges[a].append((b+N, 0))
    edges[b].append((a+N, 0))

from heapq import heappush, heappop
INF = 10 ** 18
def dijkstra(s, n, connect): #(始点, ノード数)
    distance = [INF] * n
    que = [(0, s)] #(distance, node)
    distance[s] = 0
    confirmed = [False] * n # ノードが確定済みかどうか
    while que:
        w,v = heappop(que)
        if distance[v]<w:
            continue
        confirmed[v] = True
        for to, cost in connect[v]: # ノード v に隣接しているノードに対して
            if confirmed[to] == False and distance[v] + cost < distance[to]:
                distance[to] = distance[v] + cost
                heappush(que, (distance[to], to))
    return distance

distance = dijkstra(1,N*2+1, edges)

for i in range(1, N+1):
    if i == 1:
        ans = 0
    else:
        ans = distance[i]+distance[i+N]
    print(ans)


0