結果

問題 No.1449 新プロランド
ユーザー tamatotamato
提出日時 2021-03-31 16:07:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 1,415 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 94,380 KB
最終ジャッジ日時 2023-08-25 16:50:00
合計ジャッジ時間 7,258 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
76,452 KB
testcase_01 AC 130 ms
78,544 KB
testcase_02 AC 161 ms
80,268 KB
testcase_03 AC 99 ms
76,856 KB
testcase_04 AC 136 ms
78,412 KB
testcase_05 AC 293 ms
94,380 KB
testcase_06 AC 267 ms
88,780 KB
testcase_07 AC 218 ms
85,152 KB
testcase_08 AC 269 ms
92,032 KB
testcase_09 AC 227 ms
85,000 KB
testcase_10 AC 239 ms
88,764 KB
testcase_11 AC 206 ms
86,728 KB
testcase_12 AC 266 ms
89,916 KB
testcase_13 AC 229 ms
84,384 KB
testcase_14 AC 192 ms
85,884 KB
testcase_15 AC 283 ms
89,676 KB
testcase_16 AC 250 ms
85,748 KB
testcase_17 AC 246 ms
86,892 KB
testcase_18 AC 87 ms
76,092 KB
testcase_19 AC 96 ms
77,496 KB
testcase_20 AC 82 ms
75,428 KB
testcase_21 AC 219 ms
86,952 KB
testcase_22 AC 183 ms
79,716 KB
testcase_23 AC 255 ms
90,448 KB
testcase_24 AC 206 ms
82,368 KB
testcase_25 AC 88 ms
76,620 KB
testcase_26 AC 111 ms
78,368 KB
testcase_27 AC 317 ms
93,524 KB
testcase_28 AC 249 ms
87,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline
    import heapq

    def dijkstra(adj, start):
        # adj: [[to, cost] * vertices], 0th index must be empty
        inf = 1 << 60
        dist = [inf] * len(adj)
        dist[start] = 0
        q = []
        heapq.heappush(q, (0, start))
        while q:
            min_dist, v_from = heapq.heappop(q)
            if min_dist > dist[v_from]:
                continue
            v_tos = adj[v_from]
            for v_to, cost in v_tos:
                if min_dist + cost < dist[v_to]:
                    dist[v_to] = min_dist + cost
                    heapq.heappush(q, (dist[v_to], v_to))
        return dist

    N, M = map(int, input().split())
    adj = [[] for _ in range(N * 1001 + 1)]
    ABC = []
    for _ in range(M):
        ABC.append(tuple(map(int, input().split())))
    T = [0] + list(map(int, input().split()))
    for a, b, c in ABC:
        ta = T[a]
        tb = T[b]
        for p in range(1001):
            if 0 < ta + p:
                adj[a + N * p].append((b + N * min(1000, p + ta), c // (p + ta) + ta))
            if 0 < tb + p:
                adj[b + N * p].append((a + N * min(1000, p + tb), c // (p + tb) + tb))
    dist = dijkstra(adj, 1)
    ans = float("inf")
    for p in range(1001):
        ans = min(ans, dist[N + N * p])
    print(ans)


if __name__ == '__main__':
    main()
0