結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2019-03-22 23:29:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,160 ms / 4,000 ms |
コード長 | 682 bytes |
コンパイル時間 | 235 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 164,820 KB |
最終ジャッジ日時 | 2024-11-23 19:09:50 |
合計ジャッジ時間 | 13,256 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
from heapq import heappop,heappush import sys input = sys.stdin.readline N,M=map(int,input().split()) table=[[] for i in range(2*N)] for i in range(M): a,b,c=map(int,input().split()) a,b=a-1,b-1 table[a].append((b,c)) table[b].append((a,c)) table[a].append((N+b,0)) table[b].append((N+a,0)) table[N+a].append((N+b,c)) table[N+b].append((N+a,c)) H=[] cost=[10**16]*(2*N) cost[0]=0 H.append((0,0)) while H: cos,pt=heappop(H) if cost[pt]<cos: continue for y,c in table[pt]: if cost[y]>cost[pt]+c: cost[y]=cost[pt]+c heappush(H,(cost[y],y)) print(0) for i in range(1,N): print(cost[i]+cost[N+i])