結果

問題 No.788 トラックの移動
ユーザー mkawa2mkawa2
提出日時 2021-02-12 01:29:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 697 bytes
コンパイル時間 764 ms
コンパイル使用メモリ 10,720 KB
実行使用メモリ 105,744 KB
最終ジャッジ日時 2023-09-25 15:13:23
合計ジャッジ時間 13,894 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,624 ms
105,744 KB
testcase_01 AC 206 ms
43,056 KB
testcase_02 AC 207 ms
42,904 KB
testcase_03 AC 210 ms
42,888 KB
testcase_04 AC 522 ms
58,148 KB
testcase_05 AC 1,557 ms
105,364 KB
testcase_06 AC 1,604 ms
105,512 KB
testcase_07 AC 200 ms
43,152 KB
testcase_08 WA -
testcase_09 AC 205 ms
42,812 KB
testcase_10 AC 204 ms
43,104 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 199 ms
42,412 KB
testcase_14 AC 200 ms
42,200 KB
testcase_15 AC 476 ms
105,504 KB
testcase_16 AC 1,088 ms
105,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def MI(): return map(int, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
inf = 10**16

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

n, m, l = MI()
l -= 1
tt = np.array(LI(), dtype="i8")

if np.sum(tt == 0) >= n-1:
    print(0)
    exit()

e = np.array(LLI(m), dtype="i8").T
g = csr_matrix((e[2], e[:2]-1), (n, n))

dd = dijkstra(g, directed=False).astype("i8")

iscar = tt > 0
ans = inf
for g in range(n):
    cur = np.sum(tt*dd[g])*2+np.min(dd[l][iscar]-dd[g][iscar])
    if cur < ans: ans = cur

print(ans)
0