結果

問題 No.2916 累進コスト最小化
ユーザー titia
提出日時 2024-10-30 04:30:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 756 ms / 3,500 ms
コード長 603 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 82,912 KB
最終ジャッジ日時 2024-10-30 04:30:43
合計ジャッジ時間 8,267 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from heapq import heappop,heappush

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

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

for i in range(M):
    x,y,r,w=map(int,input().split())
    x-=1
    y-=1
    E[x].append((y,r,w))
    E[y].append((x,r,w))

ANS=[]

for i in range(1,C+1):
    DP=[-1]*N
    DP[0]=i
    Q=[(-i,0)]

    while Q:
        now,ind=heappop(Q)

        if DP[ind]!=-now:
            continue

        now=-now

        for to,r,w in E[ind]:
            if DP[to]<now-(now//r+w):
                DP[to]=now-(now//r+w)
                heappush(Q,(-DP[to],to))

    print(DP[-1])
0