結果

問題 No.2739 Time is money
コンテスト
ユーザー 👑 rin204
提出日時 2024-04-20 13:07:04
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 667 ms / 2,000 ms
+ 916µs
コード長 625 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 91 ms
コンパイル使用メモリ 64,384 KB
実行使用メモリ 95,152 KB
最終ジャッジ日時 2026-10-20 22:15:26
合計ジャッジ時間 14,311 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
0