結果
問題 | No.1449 新プロランド |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:42:03 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,197 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 79,292 KB |
最終ジャッジ日時 | 2025-03-31 17:43:20 |
合計ジャッジ時間 | 2,735 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 4 |
ソースコード
import heapqdef main():import sysinput = sys.stdin.read().split()idx = 0N = int(input[idx])idx += 1M = int(input[idx])idx += 1edges = [[] for _ in range(N+1)]for _ in range(M):a = int(input[idx])idx += 1b = int(input[idx])idx += 1c = int(input[idx])idx += 1edges[a].append((b, c))edges[b].append((a, c))T = list(map(int, input[idx:idx+N]))idx += Nt_list = [0] * (N + 1) # t_list[i] is T_i for town ifor i in range(N):t_list[i + 1] = T[i]# Using a priority queue: (time, town, current_p)heap = []heapq.heappush(heap, (0, 1, 0))# dist is a dictionary of dictionaries. dist[town][p] = min_timedist = [dict() for _ in range(N + 1)]dist[1][0] = 0while heap:current_time, u, p_current = heapq.heappop(heap)if u == N:print(current_time)return# Check if the current recorded time is the smallestif p_current not in dist[u] or dist[u][p_current] < current_time:continue# Calculate new p after eating in town uT_u = t_list[u]p_new = p_current + T_ufor v, c in edges[u]:if v == u:continue # Should not happen as per the problem's input# Calculate move timemove_time = c // p_newtotal_time = current_time + T_u + move_time# Check if we can update the state for town v with p_newif v == N:# Update the answer immediatelyprint(total_time)returnelse:if p_new in dist[v]:if dist[v][p_new] <= total_time:continue# Update if this is a better pathdist[v][p_new] = total_timeheapq.heappush(heap, (total_time, v, p_new))# According to the problem statement, it's guaranteed to reach N, so this line is a fallbackprint(-1)if __name__ == "__main__":main()