結果

問題 No.807 umg tours
ユーザー convexineqconvexineq
提出日時 2021-04-06 08:53:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,422 ms / 4,000 ms
コード長 820 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 168,744 KB
最終ジャッジ日時 2023-08-30 20:13:10
合計ジャッジ時間 17,063 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
75,636 KB
testcase_01 AC 86 ms
75,484 KB
testcase_02 AC 93 ms
75,672 KB
testcase_03 AC 90 ms
75,728 KB
testcase_04 AC 84 ms
75,708 KB
testcase_05 AC 87 ms
75,660 KB
testcase_06 AC 94 ms
76,048 KB
testcase_07 AC 94 ms
75,408 KB
testcase_08 AC 76 ms
71,296 KB
testcase_09 AC 80 ms
71,204 KB
testcase_10 AC 78 ms
71,308 KB
testcase_11 AC 860 ms
139,916 KB
testcase_12 AC 821 ms
126,860 KB
testcase_13 AC 1,116 ms
146,832 KB
testcase_14 AC 603 ms
108,244 KB
testcase_15 AC 483 ms
101,580 KB
testcase_16 AC 1,104 ms
149,392 KB
testcase_17 AC 1,422 ms
163,724 KB
testcase_18 AC 1,408 ms
162,824 KB
testcase_19 AC 1,328 ms
160,256 KB
testcase_20 AC 712 ms
121,612 KB
testcase_21 AC 718 ms
123,140 KB
testcase_22 AC 383 ms
97,940 KB
testcase_23 AC 336 ms
93,596 KB
testcase_24 AC 651 ms
153,956 KB
testcase_25 AC 1,416 ms
168,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
def dijkstra(g,start):
    n = len(g)
    INF = 1<<61
    dist = [INF]*(n) #startからの最短距離
    dist[start] = 0
    q = [(0,start)] #(そこまでの距離、点)
    while q:
        dv,v = heappop(q)
        if dist[v] < dv: continue
        for to, cost in g[v]:
            if dv + cost < dist[to]:
                dist[to] = dv + cost
                heappush(q, (dist[to], to))
    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((b,c))
    g[b].append((a,c))
    g[a].append((b+n,0))
    g[b].append((a+n,0))
    g[a+n].append((b+n,c))
    g[b+n].append((a+n,c))
    
dist = dijkstra(g,0)
for i in range(n):
    if i: print(dist[i] + dist[i+n])
    else: print(0)
0