結果

問題 No.2739 Time is money
ユーザー lloyz
提出日時 2024-05-01 20:19:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 897 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 131,372 KB
最終ジャッジ日時 2024-11-22 02:37:55
合計ジャッジ時間 14,107 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
from collections import defaultdict

n, m, x = map(int, input().split())
G = defaultdict(list)
for _ in range(m):
    u, v, c, t = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, c + t * x))
    G[v].append((u, c + t * x))
INF = 10**18
DP = [INF for _ in range(n)]
DP[0] = 0
H = [(0, 0)]
while H:
    cc, cp = heappop(H)
    if cc > DP[cp]:
        continue
    for np, dc in G[cp]:
        nc = cc + dc
        if nc >= DP[np]:
            continue
        DP[np] = nc
        heappush(H, (nc, np))
ans = DP[n - 1]
if ans == INF:
    ans = -1
else:
    ans = (ans + x - 1) // x
print(ans)
0