結果
問題 | No.788 トラックの移動 |
ユーザー | H3PO4 |
提出日時 | 2021-02-04 09:52:30 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,627 ms / 2,000 ms |
コード長 | 885 bytes |
コンパイル時間 | 425 ms |
コンパイル使用メモリ | 10,948 KB |
実行使用メモリ | 149,644 KB |
最終ジャッジ日時 | 2023-08-21 17:36:14 |
合計ジャッジ時間 | 13,576 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,627 ms
105,720 KB |
testcase_01 | AC | 203 ms
43,064 KB |
testcase_02 | AC | 205 ms
43,176 KB |
testcase_03 | AC | 202 ms
43,280 KB |
testcase_04 | AC | 516 ms
58,476 KB |
testcase_05 | AC | 1,552 ms
105,468 KB |
testcase_06 | AC | 1,614 ms
105,696 KB |
testcase_07 | AC | 204 ms
43,388 KB |
testcase_08 | AC | 201 ms
43,452 KB |
testcase_09 | AC | 204 ms
43,412 KB |
testcase_10 | AC | 204 ms
43,452 KB |
testcase_11 | AC | 208 ms
43,388 KB |
testcase_12 | AC | 202 ms
43,296 KB |
testcase_13 | AC | 205 ms
42,484 KB |
testcase_14 | AC | 206 ms
42,344 KB |
testcase_15 | AC | 491 ms
105,780 KB |
testcase_16 | AC | 1,100 ms
149,644 KB |
ソースコード
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())), dtype=np.int64) nonzero = np.nonzero(T)[0] d = defaultdict(lambda: 2 * 10 ** 6) 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) if len(nonzero) == 1: print(0) exit() matr = csr_matrix((length, (frm, to)), shape=(N, N)) way = dijkstra(matr, directed=False).astype(np.int64) 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)