結果
問題 |
No.17 2つの地点に泊まりたい
|
ユーザー |
|
提出日時 | 2019-10-25 00:24:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 802 bytes |
コンパイル時間 | 67 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 16,384 KB |
最終ジャッジ日時 | 2024-07-18 09:00:24 |
合計ジャッジ時間 | 2,437 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 WA * 2 |
ソースコード
from collections import defaultdict from heapq import heappop, heappush N = int(input()) stopCost = [int(input()) for _ in range(N)] edges = [[] for _ in range(N)] M = int(input()) for _ in range(M): fr, to, cost = map(int, input().split()) edges[fr].append((to, cost)) edges[to].append((fr, cost)) minDist = defaultdict(lambda : float('inf')) que = [((0, 0, 0, set((0, N - 1))))] while que: now, cnt, d, stop = heappop(que) if minDist[(now, cnt, now in stop)] <= d: continue minDist[(now, cnt, now in stop)] = d if not now in stop and cnt < 2: que.append((now, cnt + 1, d + stopCost[now], stop.copy() | set((now,)))) for to, cost in edges[now]: heappush(que, (to, cnt, d + cost, stop.copy())) ans = minDist[(N - 1, 2, True)] print(ans)