結果

問題 No.848 なかよし旅行
ユーザー H3PO4H3PO4
提出日時 2021-02-24 18:31:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,454 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 249,972 KB
最終ジャッジ日時 2024-04-25 14:25:18
合計ジャッジ時間 38,607 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,349 ms
74,600 KB
testcase_01 AC 991 ms
56,588 KB
testcase_02 AC 996 ms
56,840 KB
testcase_03 AC 995 ms
56,836 KB
testcase_04 AC 1,019 ms
56,708 KB
testcase_05 AC 999 ms
56,844 KB
testcase_06 AC 1,011 ms
56,580 KB
testcase_07 AC 992 ms
56,428 KB
testcase_08 AC 995 ms
56,984 KB
testcase_09 AC 1,006 ms
56,984 KB
testcase_10 AC 1,000 ms
56,992 KB
testcase_11 AC 1,217 ms
177,120 KB
testcase_12 AC 1,224 ms
207,532 KB
testcase_13 AC 1,297 ms
231,364 KB
testcase_14 AC 1,134 ms
215,460 KB
testcase_15 AC 1,272 ms
203,224 KB
testcase_16 AC 1,449 ms
249,720 KB
testcase_17 AC 1,285 ms
183,728 KB
testcase_18 AC 1,177 ms
170,496 KB
testcase_19 AC 1,147 ms
185,124 KB
testcase_20 AC 1,175 ms
243,692 KB
testcase_21 AC 1,378 ms
186,528 KB
testcase_22 AC 1,400 ms
71,052 KB
testcase_23 AC 1,195 ms
243,860 KB
testcase_24 AC 1,022 ms
56,452 KB
testcase_25 AC 1,454 ms
249,972 KB
testcase_26 AC 1,001 ms
56,332 KB
testcase_27 AC 1,000 ms
56,208 KB
testcase_28 AC 1,006 ms
56,332 KB
testcase_29 AC 1,019 ms
56,964 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()

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