結果

問題 No.2739 Time is money
ユーザー 👑 rin204rin204
提出日時 2024-04-20 13:07:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 691 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 110,964 KB
最終ジャッジ日時 2024-04-20 13:07:21
合計ジャッジ時間 10,529 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,864 KB
testcase_01 AC 39 ms
52,480 KB
testcase_02 AC 243 ms
95,360 KB
testcase_03 AC 547 ms
103,220 KB
testcase_04 AC 228 ms
94,720 KB
testcase_05 AC 444 ms
95,768 KB
testcase_06 AC 494 ms
99,968 KB
testcase_07 AC 654 ms
110,776 KB
testcase_08 AC 675 ms
110,964 KB
testcase_09 AC 679 ms
110,760 KB
testcase_10 AC 413 ms
108,544 KB
testcase_11 AC 691 ms
110,924 KB
testcase_12 AC 452 ms
109,952 KB
testcase_13 AC 438 ms
109,824 KB
testcase_14 AC 441 ms
110,208 KB
testcase_15 AC 378 ms
110,176 KB
testcase_16 AC 351 ms
104,192 KB
testcase_17 AC 669 ms
110,208 KB
testcase_18 AC 641 ms
110,260 KB
testcase_19 AC 424 ms
109,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

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

dist = [1 << 60] * n
dist[0] = 0
hq = [0]
while hq:
    tmp = heappop(hq)
    d = tmp // n
    pos = tmp - d * n
    if dist[pos] < d:
        continue
    for to, cost in edges[pos]:
        if dist[to] > d + cost:
            dist[to] = d + cost
            heappush(hq, to + n * dist[to])

ans = (dist[-1] + x - 1) // x if dist[-1] != 1 << 60 else -1
print(ans)
0