結果

問題 No.1449 新プロランド
ユーザー ygd.ygd.
提出日時 2021-03-31 15:27:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 81,016 KB
最終ジャッジ日時 2023-08-25 16:48:35
合計ジャッジ時間 6,244 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
76,388 KB
testcase_01 AC 120 ms
77,520 KB
testcase_02 AC 139 ms
77,872 KB
testcase_03 AC 86 ms
76,196 KB
testcase_04 AC 120 ms
77,700 KB
testcase_05 AC 234 ms
80,544 KB
testcase_06 AC 191 ms
79,448 KB
testcase_07 AC 160 ms
78,816 KB
testcase_08 AC 206 ms
79,692 KB
testcase_09 AC 176 ms
78,764 KB
testcase_10 AC 153 ms
78,840 KB
testcase_11 AC 134 ms
78,520 KB
testcase_12 AC 182 ms
78,884 KB
testcase_13 AC 187 ms
78,744 KB
testcase_14 AC 129 ms
78,664 KB
testcase_15 AC 188 ms
79,324 KB
testcase_16 AC 164 ms
78,476 KB
testcase_17 AC 174 ms
79,172 KB
testcase_18 AC 75 ms
71,280 KB
testcase_19 AC 75 ms
71,512 KB
testcase_20 AC 74 ms
71,688 KB
testcase_21 AC 137 ms
78,312 KB
testcase_22 AC 128 ms
77,980 KB
testcase_23 AC 142 ms
78,756 KB
testcase_24 AC 162 ms
78,540 KB
testcase_25 AC 78 ms
71,636 KB
testcase_26 AC 100 ms
77,236 KB
testcase_27 AC 251 ms
81,016 KB
testcase_28 AC 192 ms
78,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
N,M = map(int,input().split()); INF = float("inf")
G = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    a-=1;b-=1
    G[a].append((c,b))
    G[b].append((c,a))
T = list(map(int,input().split()))
MAX = pow(10,3) + 10
#dp[i][j]: i番目の街にいて、おにぎりを計j分食べた時の最小値
dp = [[INF]*MAX for _ in range(N)]
#dp[0][T[0]] = 0

#S:start, V: node, E: Edge, G: Graph
V = len(G)
PQ = []
s = 0
heappush(PQ,(0,s,T[0])) #時間:c,町:v,おにぎり:p
dp[0][T[0]] = T[0]
  
while PQ:
    c,v,p = heappop(PQ) #おにぎりを食べて到着
    #print(c,v,p,dp[v][p])
    #ここで食べる
    #print(c,v,p,dp[v][p])
    #if dp[v][p] < c:
    #    continue
    #dp[v][p] = c
    for dis,u in G[v]:
        np = min(p + T[u], 1001)
        if dp[u][np] <= dis//p + dp[v][p] + T[u]:
            continue
        dp[u][np] = dis//p + dp[v][p] + T[u]
        #print(u,dp[u][np])
        heappush(PQ,(dp[u][np], u, np))
#print(dp)
ans = min(dp[N-1])
print(ans)
0