結果

問題 No.17 2つの地点に泊まりたい
ユーザー mlihua09mlihua09
提出日時 2020-09-13 02:46:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 227 ms / 5,000 ms
コード長 510 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 43,328 KB
最終ジャッジ日時 2023-08-30 20:08:11
合計ジャッジ時間 9,664 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 199 ms
42,724 KB
testcase_01 AC 198 ms
42,752 KB
testcase_02 AC 227 ms
43,208 KB
testcase_03 AC 207 ms
43,076 KB
testcase_04 AC 199 ms
42,852 KB
testcase_05 AC 205 ms
42,616 KB
testcase_06 AC 204 ms
43,088 KB
testcase_07 AC 201 ms
42,960 KB
testcase_08 AC 213 ms
42,752 KB
testcase_09 AC 205 ms
43,024 KB
testcase_10 AC 204 ms
42,652 KB
testcase_11 AC 205 ms
43,164 KB
testcase_12 AC 202 ms
42,720 KB
testcase_13 AC 199 ms
43,240 KB
testcase_14 AC 197 ms
42,980 KB
testcase_15 AC 198 ms
42,936 KB
testcase_16 AC 198 ms
43,116 KB
testcase_17 AC 197 ms
43,092 KB
testcase_18 AC 200 ms
43,032 KB
testcase_19 AC 198 ms
43,328 KB
testcase_20 AC 196 ms
42,940 KB
testcase_21 AC 194 ms
42,888 KB
testcase_22 AC 201 ms
43,124 KB
testcase_23 AC 201 ms
42,776 KB
testcase_24 AC 202 ms
42,804 KB
testcase_25 AC 198 ms
42,672 KB
testcase_26 AC 207 ms
42,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

from scipy.sparse.csgraph import shortest_path

import numpy as np

S = np.array([int(input()) for i in range(N)])

D = np.zeros((N, N), dtype=int)

M = int(input())

for i in range(M):
    a, b, c = map(int, input().split())
    
    D[a, b] = c
    D[b, a] = c
    
X = shortest_path(D, directed=False)

from itertools import permutations

ans = 10 ** 9

for i, j in permutations(range(1, N - 1), r=2):
    
    ans = min(ans, S[i] + S[j] + X[0, i] + X[i, j] + X[j, N - 1])
print(int(ans))
0