結果
問題 |
No.1449 新プロランド
|
ユーザー |
![]() |
提出日時 | 2023-02-09 23:27:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 351 ms / 2,000 ms |
コード長 | 1,156 bytes |
コンパイル時間 | 292 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 81,364 KB |
最終ジャッジ日時 | 2024-12-24 02:11:46 |
合計ジャッジ時間 | 5,679 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
import heapq import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 1 << 62 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 = [(0, 0, 0)] # time, now, eat while pq: ds, s, P = heapq.heappop(pq) 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, (ds + dt, t, P + dt)) else: if dist[t][P] > ds + dt // P: dist[t][P] = ds + dt // P heapq.heappush(pq, (ds + dt // P, t, P)) ans = inf for i in range(1001): ans = min(ans, dist[N-1][i]) print(ans) main()