結果

問題 No.2739 Time is money
ユーザー noriocnorioc
提出日時 2024-04-22 02:15:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,411 ms / 2,000 ms
コード長 813 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 196,012 KB
最終ジャッジ日時 2024-04-22 02:15:32
合計ジャッジ時間 14,328 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,760 KB
testcase_01 AC 39 ms
54,144 KB
testcase_02 AC 274 ms
117,524 KB
testcase_03 AC 733 ms
149,868 KB
testcase_04 AC 262 ms
117,180 KB
testcase_05 AC 480 ms
126,324 KB
testcase_06 AC 928 ms
153,764 KB
testcase_07 AC 1,002 ms
179,364 KB
testcase_08 AC 642 ms
164,492 KB
testcase_09 AC 821 ms
166,844 KB
testcase_10 AC 481 ms
156,228 KB
testcase_11 AC 1,411 ms
196,012 KB
testcase_12 AC 409 ms
181,900 KB
testcase_13 AC 403 ms
181,780 KB
testcase_14 AC 382 ms
168,232 KB
testcase_15 AC 803 ms
164,548 KB
testcase_16 AC 264 ms
140,784 KB
testcase_17 AC 1,308 ms
188,860 KB
testcase_18 AC 1,251 ms
181,684 KB
testcase_19 AC 947 ms
159,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heappush, heappop

N, M, X = map(int, input().split())
adj = defaultdict(list)
for _ in range(M):
    u, v, C, T = map(int, input().split())
    u -= 1
    v -= 1
    adj[u].append((v, C, T))
    adj[v].append((u, C, T))

q = [(0, 0, 0)]  # (time, money, 頂点)
used = set()
while q:
    time, money, v = heappop(q)
    money = -money
    if v == N-1:
        print(time)
        exit()
    if v in used: continue
    used.add(v)

    for to, c, t in adj[v]:
        if to in used: continue
        if money >= c:
            heappush(q, (time+t, -(money-c), to))
        else:
            lack = c - money
            d = (lack + X - 1) // X
            m2 = money + X * d - c
            t2 = time + d + t
            heappush(q, (t2, -m2, to))

print(-1)
0