結果
| 問題 |
No.2739 Time is money
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 13:07:04 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 757 ms / 2,000 ms |
| コード長 | 625 bytes |
| コンパイル時間 | 284 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 111,084 KB |
| 最終ジャッジ日時 | 2024-10-12 08:31:54 |
| 合計ジャッジ時間 | 11,862 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
from heapq import heappop, heappush
n, m, x = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
u, v, c, t = map(int, input().split())
c += t * x
u -= 1
v -= 1
edges[u].append((v, c))
edges[v].append((u, c))
dist = [1 << 60] * n
dist[0] = 0
hq = [0]
while hq:
tmp = heappop(hq)
d = tmp // n
pos = tmp - d * n
if dist[pos] < d:
continue
for to, cost in edges[pos]:
if dist[to] > d + cost:
dist[to] = d + cost
heappush(hq, to + n * dist[to])
ans = (dist[-1] + x - 1) // x if dist[-1] != 1 << 60 else -1
print(ans)