結果

問題 No.17 2つの地点に泊まりたい
ユーザー 👑 rin204rin204
提出日時 2022-07-02 20:01:10
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 112 ms / 5,000 ms
コード長 603 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 77,664 KB
最終ジャッジ日時 2023-08-18 12:01:22
合計ジャッジ時間 4,236 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,332 KB
testcase_01 AC 72 ms
71,260 KB
testcase_02 AC 93 ms
76,280 KB
testcase_03 AC 90 ms
76,592 KB
testcase_04 AC 84 ms
76,236 KB
testcase_05 AC 102 ms
76,672 KB
testcase_06 AC 94 ms
76,428 KB
testcase_07 AC 87 ms
76,404 KB
testcase_08 AC 112 ms
77,664 KB
testcase_09 AC 112 ms
77,640 KB
testcase_10 AC 92 ms
76,668 KB
testcase_11 AC 95 ms
76,524 KB
testcase_12 AC 73 ms
71,456 KB
testcase_13 AC 73 ms
71,552 KB
testcase_14 AC 72 ms
71,144 KB
testcase_15 AC 74 ms
71,136 KB
testcase_16 AC 72 ms
71,332 KB
testcase_17 AC 79 ms
76,532 KB
testcase_18 AC 86 ms
76,232 KB
testcase_19 AC 87 ms
76,464 KB
testcase_20 AC 81 ms
76,428 KB
testcase_21 AC 79 ms
75,948 KB
testcase_22 AC 89 ms
76,620 KB
testcase_23 AC 98 ms
76,512 KB
testcase_24 AC 96 ms
76,400 KB
testcase_25 AC 78 ms
75,892 KB
testcase_26 AC 102 ms
76,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = [int(input()) for _ in range(n)]
m = int(input())
inf = 1 << 30
dist = [[inf] * n for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dist[a][b] = c
    dist[b][a] = c
for i in range(n):
    dist[i][i] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

ans = inf
for i in range(1, n - 1):
    for j in range(1, n - 1):
        if i == j:
            continue
        tmp = dist[0][i] + dist[i][j] + dist[j][-1] + S[i] + S[j]
        ans = min(ans, tmp)
print(ans)
0