結果

問題 No.1449 新プロランド
ユーザー tamatotamato
提出日時 2021-03-31 16:04:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 1,519 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 87,668 KB
実行使用メモリ 93,432 KB
最終ジャッジ日時 2023-08-25 16:49:59
合計ジャッジ時間 6,791 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
76,452 KB
testcase_01 AC 124 ms
78,500 KB
testcase_02 AC 158 ms
80,708 KB
testcase_03 AC 95 ms
76,828 KB
testcase_04 AC 134 ms
78,724 KB
testcase_05 AC 271 ms
93,172 KB
testcase_06 AC 246 ms
88,220 KB
testcase_07 AC 204 ms
85,936 KB
testcase_08 AC 242 ms
90,800 KB
testcase_09 AC 215 ms
84,764 KB
testcase_10 AC 223 ms
87,956 KB
testcase_11 AC 195 ms
87,012 KB
testcase_12 AC 245 ms
90,212 KB
testcase_13 AC 216 ms
84,280 KB
testcase_14 AC 180 ms
85,552 KB
testcase_15 AC 265 ms
89,332 KB
testcase_16 AC 230 ms
85,620 KB
testcase_17 AC 232 ms
86,368 KB
testcase_18 AC 83 ms
76,456 KB
testcase_19 AC 88 ms
77,548 KB
testcase_20 AC 78 ms
75,476 KB
testcase_21 AC 206 ms
85,812 KB
testcase_22 AC 173 ms
79,720 KB
testcase_23 AC 231 ms
90,700 KB
testcase_24 AC 195 ms
82,684 KB
testcase_25 AC 82 ms
76,400 KB
testcase_26 AC 104 ms
78,224 KB
testcase_27 AC 274 ms
93,432 KB
testcase_28 AC 227 ms
87,424 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 <= 1000:
                adj[a + N * p].append((b + N * (p + ta), c // (p + ta) + ta))
            if 0 < tb + p <= 1000:
                adj[b + N * p].append((a + N * (p + tb), c // (p + tb) + tb))
        adj[a + N * 1000].append((b + N * 1000, ta))
        adj[b + N * 1000].append((a + N * 1000, 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