結果

問題 No.1449 新プロランド
ユーザー rlangevinrlangevin
提出日時 2023-01-22 10:35:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 1,538 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 95,644 KB
最終ジャッジ日時 2023-08-25 16:54:28
合計ジャッジ時間 7,081 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
76,652 KB
testcase_01 AC 121 ms
78,516 KB
testcase_02 AC 167 ms
80,576 KB
testcase_03 AC 105 ms
78,304 KB
testcase_04 AC 136 ms
79,040 KB
testcase_05 AC 284 ms
95,644 KB
testcase_06 AC 249 ms
89,188 KB
testcase_07 AC 220 ms
87,748 KB
testcase_08 AC 255 ms
93,552 KB
testcase_09 AC 220 ms
85,404 KB
testcase_10 AC 246 ms
90,724 KB
testcase_11 AC 200 ms
89,592 KB
testcase_12 AC 256 ms
91,408 KB
testcase_13 AC 213 ms
84,940 KB
testcase_14 AC 179 ms
88,300 KB
testcase_15 AC 260 ms
90,828 KB
testcase_16 AC 222 ms
86,920 KB
testcase_17 AC 243 ms
88,364 KB
testcase_18 AC 91 ms
76,496 KB
testcase_19 AC 110 ms
83,344 KB
testcase_20 AC 83 ms
75,496 KB
testcase_21 AC 215 ms
87,584 KB
testcase_22 AC 164 ms
80,164 KB
testcase_23 AC 226 ms
91,696 KB
testcase_24 AC 212 ms
83,312 KB
testcase_25 AC 102 ms
79,244 KB
testcase_26 AC 116 ms
78,540 KB
testcase_27 AC 273 ms
95,244 KB
testcase_28 AC 260 ms
88,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
inf = float('inf')


def dijkstra(s, g, N):
    # ゴールがない場合はg=-1とする。

    def cost(v, m):
        return v * N + m

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    Q = [cost(0, s)]
    while Q:
        c, m = divmod(heappop(Q), N)
        if seen[m]:
            continue
        seen[m] = True
        dist[m] = c
        if m == g:
            return dist

        #------heapをアップデートする。--------
        for u, C in G[m]:
            if seen[u]:
                continue
            newdist = dist[m] + C

            #------------------------------------
            if newdist >= mindist[u]:
                continue
            mindist[u] = newdist
            heappush(Q, cost(newdist, u))
    return dist

def f(n, m):
    return n * (mx + 1) + m

N, M = map(int, input().split())
mx = 1001
N *= mx + 1
G = [[] for i in range(N)]
A, B, C = [0] * M, [0] * M, [0] * M
for i in range(M):
    A[i], B[i], C[i] = map(int, input().split())
    A[i], B[i] = A[i] - 1, B[i] - 1
    
T = list(map(int, input().split()))
for i in range(M):
    for p in range(mx + 1):
        if p + T[A[i]]:
            G[f(A[i], p)].append((f(B[i], min(mx, p + T[A[i]])), C[i]//(p + T[A[i]]) + T[A[i]]))
        if p + T[B[i]]:
            G[f(B[i], p)].append((f(A[i], min(mx, p + T[B[i]])), C[i]//(p + T[B[i]]) + T[B[i]]))
        
D = dijkstra(f(0, 0), -1, N)
ans = inf
for i in range(mx + 1):
    ans = min(ans, D[f(N//(mx + 1) - 1, i)])
print(ans)
0