結果
問題 |
No.807 umg tours
|
ユーザー |
|
提出日時 | 2023-11-17 11:10:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,178 ms / 4,000 ms |
コード長 | 895 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 164,504 KB |
最終ジャッジ日時 | 2024-09-26 05:20:18 |
合計ジャッジ時間 | 13,316 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,M = map(int,input().split()) e = [[] for _ in range(2*N)] for _ in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 e[a].append((b,c)) e[a].append((b+N,0)) e[b].append((a,c)) e[b].append((a+N,0)) e[b+N].append((a+N,c)) e[a+N].append((b+N,c)) INF = (1<<60) def dijkstra(s,e): N = len(e) dist = [INF]*N dist[s]=0 h = [] heappush(h,(0,s)) while h: nw,v = heappop(h) if dist[v]!=nw: continue for iv,ic in e[v]: nc = ic + nw if nc < dist[iv]: dist[iv] = nc heappush(h,(nc,iv)) return dist D = dijkstra(0,e) for i in range(N): print(min(D[i]+D[i+N],2*D[i])) # print(D[i],D[i+N])