結果

問題 No.2739 Time is money
ユーザー titia
提出日時 2024-12-11 06:06:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,252 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 161,152 KB
最終ジャッジ日時 2024-12-11 06:07:17
合計ジャッジ時間 18,437 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from heapq import heappop,heappush

N,M,X=map(int,input().split())

E=[[] for i in range(N+1)]

for i in range(M):
    x,y,c,t=map(int,input().split())
    E[x].append((y,t,c))
    E[y].append((x,t,c))

DIS=[(1<<60,1<<60)]*(N+1)
DIS[1]=(0,0)

Q=[(0,0,1)]

while Q:
    x,y,town=heappop(Q)
    if DIS[town]!=(x,y):
        continue

    for to,time,cost in E[town]:
        z=x+time
        w=y+cost

        z+=w//X
        w%=X

        if DIS[to]>(z,w):
            DIS[to]=(z,w)
            heappush(Q,(z,w,to))

#print(DIS[N])

if DIS[N][0]>=1<<58:
    print(-1)
else:
    ANS=DIS[N][0]
    if DIS[N][1]>0:
        ANS+=1
    print(ANS)
        
0