結果

問題 No.2739 Time is money
ユーザー sk4rdsk4rd
提出日時 2024-04-21 02:17:06
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,019 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 148,648 KB
最終ジャッジ日時 2024-04-21 02:17:25
合計ジャッジ時間 12,721 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
57,856 KB
testcase_01 AC 42 ms
52,480 KB
testcase_02 AC 249 ms
115,072 KB
testcase_03 AC 777 ms
134,448 KB
testcase_04 AC 252 ms
114,592 KB
testcase_05 AC 568 ms
118,944 KB
testcase_06 AC 733 ms
132,020 KB
testcase_07 AC 877 ms
146,260 KB
testcase_08 AC 968 ms
147,856 KB
testcase_09 AC 920 ms
147,628 KB
testcase_10 AC 422 ms
136,832 KB
testcase_11 AC 961 ms
148,648 KB
testcase_12 AC 478 ms
146,636 KB
testcase_13 AC 485 ms
146,628 KB
testcase_14 AC 389 ms
134,784 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.buffer.readline()
inputstr = lambda: sys.stdin.readline()[:-1]

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
            r = rem[v] + wt*x-value

            if d[nv] > d[v] + cost or (d[nv] == d[v]+cost and rem[nv] < r):
                d[nv] = d[v] + cost
                rem[nv] = r
                heappush(q, (d[nv], nv))

    #print(rem)
    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(res)
print(-1 if res[-1] == INF else res[-1])
0