結果

問題 No.2739 Time is money
ユーザー sk4rdsk4rd
提出日時 2024-04-21 02:07:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 149,088 KB
最終ジャッジ日時 2024-04-21 02:07:41
合計ジャッジ時間 17,551 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
54,484 KB
testcase_01 AC 46 ms
53,264 KB
testcase_02 AC 369 ms
113,720 KB
testcase_03 WA -
testcase_04 AC 352 ms
112,952 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 635 ms
143,708 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 550 ms
138,260 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 785 ms
131,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
INF = float("inf")

def dijkstra(graph, n, s):
    d = [INF] * n
    rem = [0] * n

    d[s] = 0
    q = [(0, s)]

    while q:
        time, v = heappop(q)
        if d[v] < time: continue
        for nv, value, t in graph[v]:
            cost = t
            wt = 0
            if rem[v] < value:
                wt = -(-(value-rem[v])//x)
                cost += wt
            
            if d[nv] > d[v] + cost:
                d[nv] = d[v] + cost
                rem[nv] = wt*x-value
                heappush(q, (d[nv], nv))
    return d

n, m, x = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    u, v, c, t = map(int, input().split())
    g[u-1].append((v-1, c, t))
    g[v-1].append((u-1, c, t))

res = dijkstra(g, n, 0)
print(-1 if res[-1] == INF else res[-1])
0