結果

問題 No.807 umg tours
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-15 12:01:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,830 ms / 4,000 ms
コード長 921 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 188,916 KB
最終ジャッジ日時 2023-08-27 02:33:16
合計ジャッジ時間 32,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 178 ms
80,848 KB
testcase_01 AC 188 ms
83,364 KB
testcase_02 AC 190 ms
84,020 KB
testcase_03 AC 187 ms
83,756 KB
testcase_04 AC 174 ms
80,696 KB
testcase_05 AC 178 ms
81,400 KB
testcase_06 AC 186 ms
83,812 KB
testcase_07 AC 187 ms
83,880 KB
testcase_08 AC 169 ms
80,140 KB
testcase_09 AC 169 ms
80,140 KB
testcase_10 AC 168 ms
80,124 KB
testcase_11 AC 1,336 ms
152,880 KB
testcase_12 AC 1,678 ms
141,540 KB
testcase_13 AC 2,088 ms
162,136 KB
testcase_14 AC 1,045 ms
119,436 KB
testcase_15 AC 767 ms
111,576 KB
testcase_16 AC 1,939 ms
167,036 KB
testcase_17 AC 2,713 ms
182,820 KB
testcase_18 AC 2,605 ms
180,796 KB
testcase_19 AC 2,308 ms
177,272 KB
testcase_20 AC 1,164 ms
133,740 KB
testcase_21 AC 1,231 ms
136,068 KB
testcase_22 AC 617 ms
106,672 KB
testcase_23 AC 588 ms
102,268 KB
testcase_24 AC 1,380 ms
171,640 KB
testcase_25 AC 2,830 ms
188,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from typing import Union
input=sys.stdin.readline

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n)]
for a,b,c in abc:
	a,b=a-1,b-1
	g[a].append([b,c])
	g[b].append([a,c])
"""
ダイクストラ
seen[v]:0にできる権利を使っていない場合のvまでの最短距離
seen[v+n]:0にできる権利を使った場合のvまでの最短距離
"""
inf=10**18
seen=[inf]*(2*n)
seen[0]=0
seen[0+n]=0
todo=[[0,0]]
from heapq import heappop,heappush
while todo:
	d,v=heappop(todo)
	if seen[v]<d:continue
	for nv,nd in g[v%n]:
		if v<n:
			if seen[nv]>seen[v]+nd:
				seen[nv]=seen[v]+nd
				heappush(todo,[seen[nv],nv])
			if seen[nv+n]>seen[v]:
				seen[nv+n]=seen[v]
				heappush(todo,[seen[nv+n],nv+n])
		else:
			if seen[nv+n]>seen[v]+nd:
				seen[nv+n]=seen[v]+nd
				heappush(todo,[seen[nv+n],nv+n])
for v in range(n):
	print(seen[v]+seen[v+n])
0