結果

問題 No.1449 新プロランド
ユーザー tktk_snsntktk_snsn
提出日時 2023-02-09 23:34:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 82,744 KB
最終ジャッジ日時 2023-08-25 16:54:37
合計ジャッジ時間 6,274 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
76,488 KB
testcase_01 AC 131 ms
78,504 KB
testcase_02 AC 161 ms
78,684 KB
testcase_03 AC 110 ms
77,852 KB
testcase_04 AC 136 ms
78,020 KB
testcase_05 AC 237 ms
82,744 KB
testcase_06 AC 213 ms
81,312 KB
testcase_07 AC 170 ms
80,008 KB
testcase_08 AC 222 ms
82,356 KB
testcase_09 AC 186 ms
79,260 KB
testcase_10 AC 189 ms
80,524 KB
testcase_11 AC 154 ms
80,076 KB
testcase_12 AC 222 ms
81,880 KB
testcase_13 AC 188 ms
79,652 KB
testcase_14 AC 144 ms
80,228 KB
testcase_15 AC 226 ms
81,624 KB
testcase_16 AC 191 ms
80,472 KB
testcase_17 AC 208 ms
80,688 KB
testcase_18 AC 77 ms
71,524 KB
testcase_19 AC 77 ms
71,520 KB
testcase_20 AC 76 ms
71,280 KB
testcase_21 AC 171 ms
80,360 KB
testcase_22 AC 153 ms
78,576 KB
testcase_23 AC 164 ms
80,100 KB
testcase_24 AC 183 ms
78,940 KB
testcase_25 AC 77 ms
71,524 KB
testcase_26 AC 112 ms
77,824 KB
testcase_27 AC 257 ms
82,404 KB
testcase_28 AC 209 ms
80,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 1 << 62


class D:
    def __init__(self, dist, now, P) -> None:
        self.dist = dist
        self.now = now
        self.P = P

    def __lt__(self, rhs):
        return self.dist < rhs.dist


def main():
    N, M = map(int, input().split())
    G = [[] for _ in range(N + N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a+N].append((b, c))
        G[b+N].append((a, c))

    T = list(map(int, input().split()))
    for i, t in enumerate(T):
        G[i].append((i+N, t))

    dist = [[inf] * 1001 for _ in range(N + N)]
    dist[0][0] = 0

    pq = [D(0, 0, 0)]    # time, now, eat
    while pq:
        X = heapq.heappop(pq)
        ds = X.dist
        s = X.now
        P = X.P
        if dist[s][P] < ds:
            continue
        for t, dt in G[s]:
            if t == s + N and P + dt <= 1000:
                if dist[t][P + dt] > ds + dt:
                    dist[t][P + dt] = ds + dt
                    heapq.heappush(pq, D(ds + dt, t, P + dt))
            else:
                if dist[t][P] > ds + dt // P:
                    dist[t][P] = ds + dt // P
                    heapq.heappush(pq, D(ds + dt // P, t, P))

    ans = inf
    for i in range(1001):
        ans = min(ans, dist[N-1][i])
    print(ans)


main()
0