結果
問題 |
No.807 umg tours
|
ユーザー |
![]() |
提出日時 | 2019-03-22 23:10:29 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 889 bytes |
コンパイル時間 | 219 ms |
コンパイル使用メモリ | 82,944 KB |
実行使用メモリ | 181,792 KB |
最終ジャッジ日時 | 2024-09-19 06:34:12 |
合計ジャッジ時間 | 17,653 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 RE * 22 |
ソースコード
from heapq import heappop,heappush import sys input = sys.stdin.readline N,M=map(int,input().split()) table=[[] for i in range(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)) H=[] cost=[10**18]*N cost[0]=0 H.append((0,0)) while H: pt,cos=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,(y,cost[y])) dp=[10**19]*N dp[0]=0 def f(x): if dp[x]!=10**19: return dp[x] for y,c in table[x]: dp[x]=min(dp[x],f(y)+c) dp[x]=min(dp[x],cost[y]) return dp[x] for i in range(N): f(i) dp2=[10**19]*N dp2[0]=0 for x in range(N): for y,c in table[x]: dp2[x]=min(dp2[x],dp[y]+c) dp2[x]=min(dp2[x],cost[y]) for i in range(N): print(dp2[i]+cost[i])