結果

問題 No.17 2つの地点に泊まりたい
ユーザー takakintakakin
提出日時 2020-05-07 22:48:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 213 ms / 5,000 ms
コード長 539 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 42,604 KB
最終ジャッジ日時 2023-09-16 08:09:38
合計ジャッジ時間 9,298 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
42,240 KB
testcase_01 AC 199 ms
42,432 KB
testcase_02 AC 212 ms
42,416 KB
testcase_03 AC 207 ms
42,412 KB
testcase_04 AC 200 ms
42,356 KB
testcase_05 AC 205 ms
42,348 KB
testcase_06 AC 213 ms
42,604 KB
testcase_07 AC 213 ms
42,364 KB
testcase_08 AC 209 ms
42,420 KB
testcase_09 AC 208 ms
42,516 KB
testcase_10 AC 207 ms
42,440 KB
testcase_11 AC 205 ms
42,388 KB
testcase_12 AC 205 ms
42,320 KB
testcase_13 AC 204 ms
42,344 KB
testcase_14 AC 201 ms
42,504 KB
testcase_15 AC 203 ms
42,328 KB
testcase_16 AC 207 ms
42,328 KB
testcase_17 AC 202 ms
42,300 KB
testcase_18 AC 203 ms
42,348 KB
testcase_19 AC 205 ms
42,464 KB
testcase_20 AC 204 ms
42,460 KB
testcase_21 AC 204 ms
42,388 KB
testcase_22 AC 208 ms
42,256 KB
testcase_23 AC 205 ms
42,428 KB
testcase_24 AC 210 ms
42,164 KB
testcase_25 AC 207 ms
42,328 KB
testcase_26 AC 208 ms
42,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
S=[int(input()) for _ in range(n)]
m=int(input())
from scipy.sparse.csgraph import floyd_warshall
table=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    table[a][b]=c
    table[b][a]=c
D=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)
ans=float("inf")
import itertools
for i,j in itertools.combinations(range(1,n-1),2):
  ans=min(ans,S[i]+S[j]+D[i][j]+min(D[0][i]+D[j][n-1],D[0][j]+D[i][n-1]))
print(int(ans))
0