結果

問題 No.2739 Time is money
ユーザー cho435
提出日時 2024-04-17 01:23:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 887 ms / 2,000 ms
コード長 474 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 117,052 KB
最終ジャッジ日時 2024-10-08 09:55:39
合計ジャッジ時間 13,579 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n, m, x = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
	a, b, c, t = list(map(int, input().split()))
	a -= 1
	b -= 1
	g[a].append((b, t*x + c))
	g[b].append((a, t*x + c))

INF = 10**18
pq = [(0, 0)]
dist = [INF] * n
while pq:
	d, v = heapq.heappop(pq)
	if dist[v]!=INF:
		continue
	dist[v] = d
	for u, c in g[v]:
		if dist[u]==INF:
			heapq.heappush(pq, (d+c, u))

if dist[n-1]==INF:
	print(-1)
else:
	print((dist[n-1]+x-1)//x)
0