結果

問題 No.1449 新プロランド
ユーザー H3PO4H3PO4
提出日時 2023-06-17 20:31:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 37,244 KB
最終ジャッジ日時 2023-08-25 16:54:47
合計ジャッジ時間 6,021 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,604 KB
testcase_01 AC 32 ms
9,392 KB
testcase_02 AC 63 ms
12,072 KB
testcase_03 AC 28 ms
9,400 KB
testcase_04 AC 29 ms
9,368 KB
testcase_05 AC 445 ms
37,244 KB
testcase_06 AC 262 ms
25,736 KB
testcase_07 AC 164 ms
20,620 KB
testcase_08 AC 308 ms
30,372 KB
testcase_09 AC 227 ms
22,128 KB
testcase_10 AC 203 ms
24,260 KB
testcase_11 AC 145 ms
21,888 KB
testcase_12 AC 291 ms
28,792 KB
testcase_13 AC 188 ms
19,952 KB
testcase_14 AC 124 ms
20,984 KB
testcase_15 AC 298 ms
27,944 KB
testcase_16 AC 210 ms
22,052 KB
testcase_17 AC 221 ms
23,388 KB
testcase_18 AC 25 ms
9,004 KB
testcase_19 AC 57 ms
15,452 KB
testcase_20 AC 21 ms
8,608 KB
testcase_21 AC 155 ms
21,172 KB
testcase_22 AC 40 ms
10,388 KB
testcase_23 AC 246 ms
28,132 KB
testcase_24 AC 135 ms
16,716 KB
testcase_25 AC 46 ms
11,680 KB
testcase_26 AC 24 ms
8,744 KB
testcase_27 AC 441 ms
36,588 KB
testcase_28 AC 318 ms
26,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappop, heappush

input = sys.stdin.buffer.readline


def dijkstra(N, G, s):
    INF = 10 ** 9
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist


N, M = map(int, input().split())
MAX_TIME = 1000
G = [[] for _ in range(N * (MAX_TIME + 1))]


def pair2int(num, time):
    return min(time, MAX_TIME) * N + num


def add_edge(s_num, t_num, s_time, eat_time, length):
    t_time = s_time + eat_time
    if not t_time:
        return
    G[pair2int(s_num, s_time)].append((pair2int(t_num, t_time), eat_time + length // t_time))


edges = []
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a, b, c))
T = tuple(map(int, input().split()))
for a, b, c in edges:
    for time in range(MAX_TIME + 1):
        add_edge(a, b, time, T[a], c)
        add_edge(b, a, time, T[b], c)

dist = dijkstra(len(G), G, pair2int(0, 0))
ans = min(dist[pair2int(N - 1, time)] for time in range(MAX_TIME + 1))
print(ans)
0