結果

問題 No.848 なかよし旅行
ユーザー H3PO4H3PO4
提出日時 2021-02-24 18:39:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 483 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 210,892 KB
最終ジャッジ日時 2023-08-07 20:07:41
合計ジャッジ時間 10,699 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 374 ms
62,340 KB
testcase_01 AC 192 ms
43,496 KB
testcase_02 AC 193 ms
43,552 KB
testcase_03 AC 192 ms
43,464 KB
testcase_04 AC 192 ms
43,516 KB
testcase_05 AC 194 ms
43,452 KB
testcase_06 AC 194 ms
43,608 KB
testcase_07 AC 197 ms
43,416 KB
testcase_08 AC 200 ms
45,876 KB
testcase_09 AC 203 ms
45,848 KB
testcase_10 AC 200 ms
45,716 KB
testcase_11 AC 321 ms
148,192 KB
testcase_12 AC 357 ms
175,348 KB
testcase_13 AC 403 ms
194,816 KB
testcase_14 AC 295 ms
180,632 KB
testcase_15 AC 370 ms
173,100 KB
testcase_16 AC 483 ms
210,500 KB
testcase_17 AC 395 ms
154,740 KB
testcase_18 AC 299 ms
142,680 KB
testcase_19 AC 295 ms
153,960 KB
testcase_20 AC 297 ms
203,872 KB
testcase_21 AC 402 ms
156,288 KB
testcase_22 AC 370 ms
59,504 KB
testcase_23 AC 308 ms
203,848 KB
testcase_24 AC 202 ms
43,336 KB
testcase_25 AC 473 ms
210,892 KB
testcase_26 AC 196 ms
43,104 KB
testcase_27 AC 192 ms
43,412 KB
testcase_28 AC 189 ms
43,452 KB
testcase_29 AC 188 ms
43,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

input = sys.stdin.buffer.readline

N, M, P, Q, T = map(int, input().split())
P -= 1
Q -= 1
edges = np.array([tuple(map(int, input().split())) for _ in range(M)]).T

matr = csr_matrix((edges[2], (edges[:2] - 1)), shape=(N, N))
way_1, way_p, way_q = dijkstra(matr, indices=(0, P, Q), directed=False).astype(int)

if way_1[P] + way_1[Q] + way_p[Q] <= T:
    print(T)
    exit()

xpy = way_p[:, None] + way_p[None, :]
xqy = way_q[:, None] + way_q[None, :]
xy1 = way_1[:, None] + way_1[None, :]
res = np.where((xy1 + xpy <= T) & (xy1 + xqy <= T), T - np.maximum(xpy, xqy), -1)
ans = res.max()
print(ans)
0