結果

問題 No.2739 Time is money
コンテスト
ユーザー 回転
提出日時 2026-04-29 16:31:50
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,748 ms / 2,000 ms
コード長 619 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 161 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 203,112 KB
最終ジャッジ日時 2026-04-29 16:32:17
合計ジャッジ時間 23,599 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq
N,M,X = list(map(int,input().split()))
edge = [[] for _ in range(N)]
for _ in range(M):
    u,v,c,t = list(map(int,input().split()))
    u -= 1;v -= 1
    edge[u].append((v,c,t))
    edge[v].append((u,c,t))

q = [(0,0,0,0)]
INF = 10**18
visited = [INF] * N
while(q):
    v,time,money,now = heapq.heappop(q)

    if(visited[now] <= v):continue
    visited[now] = v

    for u,c,t in edge[now]:
        next_time = time + t
        next_money = money + c
        next_v = next_time + -(-next_money//X)
        heapq.heappush(q,(next_v,next_time,next_money,u))
print(visited[-1] if visited[-1] != INF else -1)
0