結果

問題 No.17 2つの地点に泊まりたい
ユーザー maspymaspy
提出日時 2020-03-05 10:46:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 898 ms / 5,000 ms
コード長 703 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 56,384 KB
最終ジャッジ日時 2024-04-22 02:11:41
合計ジャッジ時間 26,788 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 839 ms
56,008 KB
testcase_01 AC 854 ms
56,144 KB
testcase_02 AC 835 ms
56,140 KB
testcase_03 AC 834 ms
55,876 KB
testcase_04 AC 851 ms
55,880 KB
testcase_05 AC 833 ms
56,132 KB
testcase_06 AC 826 ms
56,000 KB
testcase_07 AC 828 ms
55,748 KB
testcase_08 AC 834 ms
56,064 KB
testcase_09 AC 837 ms
56,384 KB
testcase_10 AC 830 ms
56,000 KB
testcase_11 AC 853 ms
56,004 KB
testcase_12 AC 838 ms
56,128 KB
testcase_13 AC 834 ms
56,132 KB
testcase_14 AC 848 ms
56,156 KB
testcase_15 AC 844 ms
55,752 KB
testcase_16 AC 898 ms
55,752 KB
testcase_17 AC 882 ms
56,136 KB
testcase_18 AC 873 ms
56,132 KB
testcase_19 AC 874 ms
56,128 KB
testcase_20 AC 854 ms
56,008 KB
testcase_21 AC 827 ms
56,128 KB
testcase_22 AC 828 ms
56,128 KB
testcase_23 AC 835 ms
56,132 KB
testcase_24 AC 839 ms
55,748 KB
testcase_25 AC 849 ms
56,144 KB
testcase_26 AC 844 ms
56,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

# %%
N = int(readline())
S = np.array([readline() for _ in range(N)], np.int64)
M = int(readline())
ABC = np.array(read().split(), np.int64)
A = ABC[::3]
B = ABC[1::3]
C = ABC[2::3]

# %%
graph = np.full((N, N), np.inf)
graph[A, B] = C


# %%
dist_mat = floyd_warshall(graph, directed=False)

# %%
cost = dist_mat[0, :][:, None] + S[:, None] + dist_mat + S[None, :] + dist_mat[N - 1, :][None, :]
np.fill_diagonal(cost, np.inf)
cost = cost[1:-1, 1:-1]
answer = int(cost.min())
print(answer)
0