結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-17 11:17:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,034 ms / 4,000 ms |
| コード長 | 903 bytes |
| コンパイル時間 | 274 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 156,384 KB |
| 最終ジャッジ日時 | 2024-09-26 05:20:56 |
| 合計ジャッジ時間 | 11,996 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / 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,s)
while h:
nw,v = divmod(heappop(h),N)
if dist[v]!=nw:
continue
for iv,ic in e[v]:
nc = ic + nw
if nc < dist[iv]:
dist[iv] = nc
heappush(h,nc*N + 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])