結果

問題 No.788 トラックの移動
ユーザー H3PO4H3PO4
提出日時 2021-02-04 09:39:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 811 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 143,176 KB
最終ジャッジ日時 2023-09-13 04:38:56
合計ジャッジ時間 12,013 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 190 ms
43,296 KB
testcase_02 AC 194 ms
43,328 KB
testcase_03 AC 197 ms
43,372 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

N, M, L = map(int, input().split())
L -= 1  # 0-indexed
T = np.array(list(map(int, input().split())))
nonzero = np.nonzero(T)[0]
d = defaultdict(lambda: 10000)
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[(a, b)] = min(d[(a, b)], c)
frm, to, length = [], [], []
for (a, b), c in d.items():
    frm.append(a)
    to.append(b)
    length.append(c)

matr = csr_matrix((length, (frm, to)), shape=(N, N))
way = dijkstra(matr, directed=False).astype(int)
ans = np.inf
for target in range(N):
    tmp = np.sum(way[target] * 2 * T)
    first = np.max(way[target][nonzero] - way[L][nonzero])
    tmp -= first
    ans = min(ans, tmp)
print(ans)
0