結果
| 問題 | No.788 トラックの移動 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-02-04 09:52:30 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                TLE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 885 bytes | 
| コンパイル時間 | 190 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 212,652 KB | 
| 最終ジャッジ日時 | 2024-12-15 07:09:02 | 
| 合計ジャッジ時間 | 27,564 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 11 TLE * 3 | 
ソースコード
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)
            
            
            
        