結果

問題 No.17 2つの地点に泊まりたい
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-04-14 10:54:10
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 641 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 78,280 KB
最終ジャッジ日時 2023-09-13 00:45:46
合計ジャッジ時間 4,607 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,756 KB
testcase_01 AC 91 ms
71,344 KB
testcase_02 AC 101 ms
77,456 KB
testcase_03 AC 116 ms
77,688 KB
testcase_04 AC 106 ms
77,324 KB
testcase_05 AC 128 ms
77,860 KB
testcase_06 AC 117 ms
77,484 KB
testcase_07 AC 111 ms
77,452 KB
testcase_08 AC 139 ms
78,192 KB
testcase_09 AC 137 ms
78,280 KB
testcase_10 AC 122 ms
77,336 KB
testcase_11 AC 127 ms
77,700 KB
testcase_12 AC 92 ms
71,828 KB
testcase_13 AC 90 ms
71,684 KB
testcase_14 AC 91 ms
71,748 KB
testcase_15 AC 91 ms
71,576 KB
testcase_16 AC 91 ms
71,684 KB
testcase_17 AC 104 ms
77,784 KB
testcase_18 AC 118 ms
77,640 KB
testcase_19 AC 115 ms
77,692 KB
testcase_20 AC 104 ms
77,292 KB
testcase_21 AC 99 ms
77,088 KB
testcase_22 AC 119 ms
77,656 KB
testcase_23 AC 120 ms
77,492 KB
testcase_24 AC 127 ms
77,812 KB
testcase_25 AC 100 ms
77,012 KB
testcase_26 AC 127 ms
77,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n = int(input())
S = [int(input()) for i in range(n)]
inf = 10**20
dis = [[inf]*n for i in range(n)]
m = int(input())
for i in range(m):
    a,b,c = map(int,input().split())
    dis[a][b] = c
    dis[b][a] = c

for i in range(n):
    dis[i][i] = 0

for k in range(n):
    for i in range(n):
        for j in range(n):
            if dis[i][k] != inf and dis[k][j] != inf:
                dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j])

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