結果

問題 No.17 2つの地点に泊まりたい
ユーザー H3PO4H3PO4
提出日時 2020-04-18 19:06:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,017 ms / 5,000 ms
コード長 558 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 56,744 KB
最終ジャッジ日時 2024-04-14 21:09:10
合計ジャッジ時間 32,972 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 983 ms
55,968 KB
testcase_01 AC 974 ms
56,488 KB
testcase_02 AC 975 ms
56,112 KB
testcase_03 AC 1,017 ms
56,360 KB
testcase_04 AC 974 ms
56,108 KB
testcase_05 AC 974 ms
56,108 KB
testcase_06 AC 972 ms
56,100 KB
testcase_07 AC 989 ms
56,104 KB
testcase_08 AC 982 ms
55,984 KB
testcase_09 AC 971 ms
56,108 KB
testcase_10 AC 970 ms
56,344 KB
testcase_11 AC 972 ms
56,744 KB
testcase_12 AC 969 ms
56,488 KB
testcase_13 AC 959 ms
56,104 KB
testcase_14 AC 972 ms
56,144 KB
testcase_15 AC 957 ms
56,104 KB
testcase_16 AC 968 ms
56,364 KB
testcase_17 AC 975 ms
56,500 KB
testcase_18 AC 963 ms
56,228 KB
testcase_19 AC 961 ms
56,236 KB
testcase_20 AC 962 ms
55,984 KB
testcase_21 AC 978 ms
56,488 KB
testcase_22 AC 971 ms
56,356 KB
testcase_23 AC 969 ms
56,356 KB
testcase_24 AC 973 ms
56,372 KB
testcase_25 AC 957 ms
56,496 KB
testcase_26 AC 979 ms
56,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

N = int(input())
S = tuple(int(input()) for _ in range(N))
M = int(input())
X = np.array([tuple(map(int, input().split())) for _ in range(M)]).T

matr = csr_matrix((X[2], (X[0], X[1])), shape=(N, N))
way = floyd_warshall(matr, directed=False).astype(int)
way[way < 0] = 10 ** 9

ans = float('inf')
for i, j in itertools.permutations(range(1, N - 1), 2):
    ans = min(ans, way[0][i] + way[i][j] + way[j][N - 1] + S[i] + S[j])
print(ans)
0