結果

問題 No.17 2つの地点に泊まりたい
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-10-25 00:24:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 14,044 KB
最終ジャッジ日時 2023-09-25 11:07:46
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,560 KB
testcase_01 AC 19 ms
8,656 KB
testcase_02 AC 19 ms
8,588 KB
testcase_03 AC 24 ms
8,796 KB
testcase_04 AC 40 ms
9,416 KB
testcase_05 AC 86 ms
11,852 KB
testcase_06 AC 78 ms
10,484 KB
testcase_07 AC 78 ms
10,908 KB
testcase_08 AC 131 ms
13,164 KB
testcase_09 AC 145 ms
14,044 KB
testcase_10 AC 39 ms
9,696 KB
testcase_11 AC 95 ms
11,228 KB
testcase_12 AC 19 ms
8,596 KB
testcase_13 AC 19 ms
8,672 KB
testcase_14 AC 19 ms
8,564 KB
testcase_15 AC 19 ms
8,644 KB
testcase_16 AC 19 ms
8,668 KB
testcase_17 AC 20 ms
8,736 KB
testcase_18 AC 21 ms
8,816 KB
testcase_19 AC 20 ms
8,632 KB
testcase_20 AC 20 ms
8,604 KB
testcase_21 AC 20 ms
8,736 KB
testcase_22 AC 25 ms
8,744 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 22 ms
8,828 KB
testcase_26 AC 132 ms
12,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0