結果

問題 No.2739 Time is money
ユーザー sk4rdsk4rd
提出日時 2024-04-21 02:43:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,334 ms / 2,000 ms
コード長 1,029 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 156,676 KB
最終ジャッジ日時 2024-04-21 02:43:28
合計ジャッジ時間 17,092 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,092 KB
testcase_01 AC 39 ms
52,736 KB
testcase_02 AC 225 ms
115,328 KB
testcase_03 AC 1,129 ms
140,888 KB
testcase_04 AC 238 ms
114,556 KB
testcase_05 AC 857 ms
123,432 KB
testcase_06 AC 955 ms
137,316 KB
testcase_07 AC 1,240 ms
152,572 KB
testcase_08 AC 1,334 ms
156,336 KB
testcase_09 AC 1,334 ms
156,168 KB
testcase_10 AC 417 ms
136,924 KB
testcase_11 AC 1,318 ms
156,676 KB
testcase_12 AC 449 ms
146,376 KB
testcase_13 AC 486 ms
146,500 KB
testcase_14 AC 399 ms
134,316 KB
testcase_15 AC 665 ms
142,636 KB
testcase_16 AC 846 ms
142,584 KB
testcase_17 AC 1,176 ms
155,680 KB
testcase_18 AC 1,207 ms
149,448 KB
testcase_19 AC 867 ms
136,592 KB
権限があれば一括ダウンロードができます

ソースコード

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, 0, s)]

    while q:
        time, rv, v = heappop(q)
        if d[v] < time: continue
        for nv, value, t in graph[v]:
            r = rv
            cost = t
            wt = 0
            if r < value:
                wt = -(-(value-r)//x)
                cost += wt
            r += 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], r, 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