結果
| 問題 | No.17 2つの地点に泊まりたい |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-25 00:20:45 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 859 bytes |
| コンパイル時間 | 113 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 17,152 KB |
| 最終ジャッジ日時 | 2024-07-18 08:55:53 |
| 合計ジャッジ時間 | 2,378 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 3 |
ソースコード
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]:
if minDist[(to, cnt, to in stop)] > d + cost:
heappush(que, (to, cnt, d + cost, stop.copy()))
ans = minDist[(N - 1, 2, True)]
print(ans)