結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー | OKCH3COOH |
提出日時 | 2019-10-25 00:20:45 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 859 bytes |
コンパイル時間 | 116 ms |
コンパイル使用メモリ | 10,988 KB |
実行使用メモリ | 14,780 KB |
最終ジャッジ日時 | 2023-09-25 11:02:10 |
合計ジャッジ時間 | 3,002 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
8,568 KB |
testcase_01 | AC | 19 ms
8,568 KB |
testcase_02 | AC | 20 ms
8,576 KB |
testcase_03 | AC | 23 ms
8,824 KB |
testcase_04 | AC | 32 ms
9,416 KB |
testcase_05 | AC | 70 ms
11,560 KB |
testcase_06 | AC | 63 ms
10,832 KB |
testcase_07 | AC | 58 ms
10,684 KB |
testcase_08 | AC | 111 ms
14,244 KB |
testcase_09 | WA | - |
testcase_10 | AC | 36 ms
9,520 KB |
testcase_11 | AC | 71 ms
11,188 KB |
testcase_12 | AC | 19 ms
8,676 KB |
testcase_13 | AC | 19 ms
8,572 KB |
testcase_14 | AC | 19 ms
8,600 KB |
testcase_15 | AC | 19 ms
8,620 KB |
testcase_16 | AC | 20 ms
8,676 KB |
testcase_17 | AC | 20 ms
8,572 KB |
testcase_18 | AC | 21 ms
8,728 KB |
testcase_19 | AC | 21 ms
8,644 KB |
testcase_20 | AC | 20 ms
8,612 KB |
testcase_21 | AC | 19 ms
8,680 KB |
testcase_22 | AC | 24 ms
8,800 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 22 ms
8,800 KB |
testcase_26 | AC | 97 ms
12,904 KB |
ソースコード
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)