Submission #47799874


Source Code Expand

#ABC164E Two Currencies

import heapq as hq

#入力受取
N,M,S=map(int,input().split()); G=[[] for _ in range(N)]
for _ in range(M):
    u,v,a,b=map(int,input().split())
    G[u-1].append((v-1,a,b));G[v-1].append((u-1,a,b))
H=[tuple(map(int,input().split())) for _ in range(N)]

#DP[i][s]: 地点iに銀貨s枚を持って到達する最短時間
DP=[[10**18]*2501 for _ in range(N)]

#heapqを用いたDijkstra法を行う
Q=[(0,0,min(S,2500))]  #経過時間, 現在地, 残銀貨
while Q:
    time,now,money=hq.heappop(Q)
    if DP[now][money]<time: continue
    DP[now][money]=time

    #両替を行う遷移
    rate,cost=H[now]
    if DP[now][min(2500,money+rate)]>time+cost:
        DP[now][min(2500,money+rate)]=time+cost
        hq.heappush(Q,(time+cost,now,min(2500,money+rate)))

    #次の目的地に移動する遷移
    for next,need,cost in G[now]:
        if money<need: continue  #おかねがたりません
        if DP[next][money-need]>time+cost:
            DP[next][money-need]=time+cost
            hq.heappush(Q,(time+cost,next,money-need))

#答えを出力
for i in range(1,N): print(min(DP[i]))

Submission Info

Submission Time
Task E - Two Currencies
User navel_tos
Language Python (PyPy 3.10-v7.3.12)
Score 500
Code Size 1166 Byte
Status AC
Exec Time 560 ms
Memory 106208 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 5
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All line_1.txt, line_2.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
line_1.txt AC 174 ms 85164 KiB
line_2.txt AC 155 ms 84216 KiB
random_01.txt AC 477 ms 103900 KiB
random_02.txt AC 559 ms 105820 KiB
random_03.txt AC 472 ms 103832 KiB
random_04.txt AC 560 ms 104904 KiB
random_05.txt AC 528 ms 103044 KiB
random_06.txt AC 515 ms 104520 KiB
random_07.txt AC 473 ms 103120 KiB
random_08.txt AC 560 ms 106012 KiB
random_09.txt AC 473 ms 102112 KiB
random_10.txt AC 527 ms 103860 KiB
random_11.txt AC 548 ms 105268 KiB
random_12.txt AC 518 ms 104064 KiB
random_13.txt AC 510 ms 103500 KiB
random_14.txt AC 480 ms 102712 KiB
random_15.txt AC 446 ms 100164 KiB
random_16.txt AC 558 ms 106208 KiB
random_17.txt AC 531 ms 104512 KiB
random_18.txt AC 481 ms 102672 KiB
random_19.txt AC 460 ms 100796 KiB
random_20.txt AC 452 ms 101892 KiB
sample_01.txt AC 101 ms 84152 KiB
sample_02.txt AC 125 ms 84568 KiB
sample_03.txt AC 133 ms 84568 KiB
sample_04.txt AC 120 ms 84892 KiB
sample_05.txt AC 109 ms 83648 KiB