結果

問題 No.807 umg tours
コンテスト
ユーザー tobusakana
提出日時 2022-12-01 01:15:32
言語 PyPy3
(7.3.17)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,202 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 408 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 182,296 KB
最終ジャッジ日時 2026-01-16 14:22:19
合計ジャッジ時間 26,784 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 一回だけコスト0で移動できるダイクストラで、各頂点への距離を「権利使った,使ってない」の二通りで求める

N,M = map(int,input().split())
G = [[] for i in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
INF = 1 << 60
dist = [[INF] * 2 for i in range(N)]
import heapq as hq
q = []
hq.heappush(q, (0, 0, False))
dist[0][True] = 0
while q:
    d,v,used = hq.heappop(q)
#    print("v",v,"d",d,"used",used)
    if dist[v][used] != INF:
        continue
    dist[v][used] = d
    for child, c in G[v]:
#        print(child,c,"used",used)
        # 権利を使える場合
        if not used:
            if dist[child][True] == INF:
#                print("権利を使って",v,"から",child,"に移動")
                hq.heappush(q, (d, child, True))
        # 権利を使わない場合
        if dist[child][used] == INF:
#            print("権利を遣わず",v,"から",child,"に移動",used)
            hq.heappush(q, (d + c, child, used))
            
#print(dist)
            
for i in range(N):
    print(dist[i][False] + dist[i][True])
            
    
0