結果

問題 No.17 2つの地点に泊まりたい
ユーザー dangodango
提出日時 2023-07-08 18:00:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 596 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 77,328 KB
最終ジャッジ日時 2023-09-29 19:22:00
合計ジャッジ時間 3,770 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
70,948 KB
testcase_01 AC 65 ms
71,188 KB
testcase_02 AC 71 ms
75,828 KB
testcase_03 AC 82 ms
76,112 KB
testcase_04 AC 75 ms
75,932 KB
testcase_05 AC 92 ms
76,632 KB
testcase_06 AC 89 ms
75,816 KB
testcase_07 AC 80 ms
76,088 KB
testcase_08 AC 105 ms
77,212 KB
testcase_09 AC 106 ms
77,328 KB
testcase_10 AC 87 ms
75,892 KB
testcase_11 AC 91 ms
76,332 KB
testcase_12 AC 66 ms
71,088 KB
testcase_13 AC 67 ms
71,364 KB
testcase_14 AC 67 ms
71,332 KB
testcase_15 AC 65 ms
71,380 KB
testcase_16 AC 68 ms
71,084 KB
testcase_17 AC 74 ms
76,112 KB
testcase_18 AC 83 ms
76,180 KB
testcase_19 AC 80 ms
76,252 KB
testcase_20 AC 75 ms
76,232 KB
testcase_21 AC 71 ms
75,316 KB
testcase_22 AC 83 ms
76,328 KB
testcase_23 AC 92 ms
76,196 KB
testcase_24 AC 89 ms
76,108 KB
testcase_25 AC 72 ms
75,312 KB
testcase_26 AC 92 ms
76,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = [int(input()) for _ in range(n)]
m = int(input())
dist = [[1 << 30] * 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 = 1 << 30
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