結果

問題 No.17 2つの地点に泊まりたい
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-24 05:26:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 613 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 66,500 KB
最終ジャッジ日時 2023-10-21 15:35:46
合計ジャッジ時間 2,583 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,512 KB
testcase_01 AC 30 ms
53,512 KB
testcase_02 AC 34 ms
59,836 KB
testcase_03 AC 42 ms
64,200 KB
testcase_04 AC 37 ms
61,956 KB
testcase_05 AC 47 ms
66,276 KB
testcase_06 AC 43 ms
64,200 KB
testcase_07 AC 39 ms
62,096 KB
testcase_08 AC 47 ms
66,500 KB
testcase_09 AC 49 ms
66,500 KB
testcase_10 AC 42 ms
64,200 KB
testcase_11 AC 47 ms
64,200 KB
testcase_12 AC 33 ms
53,512 KB
testcase_13 AC 32 ms
53,512 KB
testcase_14 AC 31 ms
53,512 KB
testcase_15 AC 30 ms
53,512 KB
testcase_16 AC 30 ms
53,512 KB
testcase_17 AC 36 ms
59,908 KB
testcase_18 AC 42 ms
62,140 KB
testcase_19 AC 45 ms
62,140 KB
testcase_20 AC 36 ms
59,892 KB
testcase_21 AC 34 ms
59,612 KB
testcase_22 AC 44 ms
64,200 KB
testcase_23 AC 47 ms
64,192 KB
testcase_24 AC 45 ms
64,200 KB
testcase_25 AC 36 ms
59,612 KB
testcase_26 AC 47 ms
66,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18

N = int(input())
S = [int(input()) for _ in range(N)]
M = int(input())
G = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    G[a][b] = c
    G[b][a] = c

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

ans = inf
for a in range(1, N - 1):
    for b in range(1, N - 1):
        if a == b:
            continue
        cost = G[0][a] + S[a] + G[a][b] + S[b] + G[b][N-1]
        ans = min(ans, cost)
print(ans)
0