結果

問題 No.788 トラックの移動
ユーザー maspy
提出日時 2020-03-17 11:48:02
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,051 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 243,424 KB
最終ジャッジ日時 2024-12-15 07:07:56
合計ジャッジ時間 24,375 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
from collections import defaultdict

# %%
N, M, L = map(int, readline().split())
T = np.array(readline().split(), np.int64)
ABC = np.array(read().split(), np.int64)
A = ABC[::3] - 1
B = ABC[1::3] - 1
C = ABC[2::3]

# %%
INF = 10 ** 12
wt = defaultdict(lambda: INF)
for a, b, c in zip(A, B, C):
    if a > b:
        a, b = b, a
    if wt[(a, b)] > c:
        wt[(a, b)] = c
A = []
B = []
C = []
for (a, b), c in wt.items():
    A.append(a)
    B.append(b)
    C.append(c)

if np.count_nonzero(T > 0) <= 1:
    print(0)
    exit()
# %%
graph = csr_matrix((C, (A, B)), (N, N))
dist = dijkstra(graph, directed=False)
# %%
dist = (dist + .5).astype(np.int64)
cost = (dist * T[None, :]).sum(axis=1) * 2
diff = -dist + dist[L - 1][None, :]
diff[:, T == 0] += 10 ** 12
cost = cost[:, None] + diff
print(cost.min())
0