結果

問題 No.2916 累進コスト最小化
ユーザー vwxyz
提出日時 2024-10-04 22:12:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 704 ms / 3,500 ms
コード長 1,386 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 97,184 KB
最終ジャッジ日時 2024-10-05 01:06:19
合計ジャッジ時間 9,790 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
#sys.set_int_max_str_digits(10**9)

N,M,C=map(int,input().split())
graph=[[] for x in range(N)]
for m in range(M):
    u,v,r,w=map(int,input().split())
    u-=1;v-=1
    graph[u].append((v,r,w))
    graph[v].append((u,r,w))
for c in range(1,C+1):
    inf=1<<30
    dist=[-inf]*N
    dist[0]=c
    queue=[(c,0)]
    while queue:
        dx,x=_heappop_max(queue)
        if dist[x]>dx:
            continue
        for y,r,w in graph[x]:
            dy=dx-dx//r-w
            if dist[y]<dy and dy>=0:
                dist[y]=dy
                _heappush_max(queue,(dy,y))
    ans=dist[N-1]
    if ans==-inf:
        ans=-1
    print(ans)
0