結果

問題 No.17 2つの地点に泊まりたい
ユーザー AEnAEn
提出日時 2022-08-24 16:18:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 608 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 75,300 KB
最終ジャッジ日時 2024-04-20 05:49:03
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,932 KB
testcase_01 AC 37 ms
53,212 KB
testcase_02 AC 47 ms
62,948 KB
testcase_03 AC 62 ms
72,884 KB
testcase_04 AC 43 ms
62,576 KB
testcase_05 AC 59 ms
69,900 KB
testcase_06 AC 57 ms
67,276 KB
testcase_07 AC 48 ms
63,568 KB
testcase_08 AC 69 ms
74,540 KB
testcase_09 AC 66 ms
74,332 KB
testcase_10 AC 69 ms
74,564 KB
testcase_11 AC 68 ms
75,300 KB
testcase_12 AC 32 ms
52,620 KB
testcase_13 AC 31 ms
52,748 KB
testcase_14 AC 33 ms
52,440 KB
testcase_15 AC 33 ms
52,888 KB
testcase_16 AC 32 ms
52,792 KB
testcase_17 AC 47 ms
65,480 KB
testcase_18 AC 58 ms
71,276 KB
testcase_19 AC 60 ms
71,124 KB
testcase_20 AC 47 ms
65,520 KB
testcase_21 AC 39 ms
62,028 KB
testcase_22 AC 61 ms
72,720 KB
testcase_23 AC 56 ms
67,336 KB
testcase_24 AC 62 ms
70,836 KB
testcase_25 AC 40 ms
61,168 KB
testcase_26 AC 61 ms
71,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = [int(input()) for _ in range(N)]
G = [list() for _ in range(N)]
from itertools import permutations

M = int(input())
cost = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    cost[i][i] = 0
for i in range(M):
    A, B, C = map(int, input().split())
    cost[A][B] = C
    cost[B][A] = C

for k in range(N):
    for i in range(N):
        for j in range(N):
            cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])

res = float('inf')
for v in permutations(range(1, N-1), 2):
    a, b = v[0], v[1]
    res = min(res, cost[0][a]+cost[a][b]+cost[b][-1]+S[a]+S[b])
print(res)
0