結果

問題 No.848 なかよし旅行
ユーザー H3PO4H3PO4
提出日時 2021-02-24 18:39:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,267 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 222,664 KB
最終ジャッジ日時 2024-04-25 14:29:13
合計ジャッジ時間 33,334 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,161 ms
74,188 KB
testcase_01 AC 858 ms
57,024 KB
testcase_02 AC 866 ms
56,652 KB
testcase_03 AC 873 ms
56,892 KB
testcase_04 AC 882 ms
56,656 KB
testcase_05 AC 885 ms
56,768 KB
testcase_06 AC 881 ms
56,652 KB
testcase_07 AC 863 ms
57,028 KB
testcase_08 AC 872 ms
57,000 KB
testcase_09 AC 879 ms
57,424 KB
testcase_10 AC 889 ms
57,256 KB
testcase_11 AC 1,037 ms
161,696 KB
testcase_12 AC 1,082 ms
184,856 KB
testcase_13 AC 1,150 ms
206,348 KB
testcase_14 AC 990 ms
192,700 KB
testcase_15 AC 1,129 ms
183,132 KB
testcase_16 AC 1,267 ms
222,332 KB
testcase_17 AC 1,129 ms
166,636 KB
testcase_18 AC 1,029 ms
153,052 KB
testcase_19 AC 1,027 ms
166,752 KB
testcase_20 AC 993 ms
216,592 KB
testcase_21 AC 1,201 ms
168,900 KB
testcase_22 AC 1,170 ms
71,748 KB
testcase_23 AC 995 ms
216,348 KB
testcase_24 AC 864 ms
56,652 KB
testcase_25 AC 1,263 ms
222,664 KB
testcase_26 AC 890 ms
56,392 KB
testcase_27 AC 874 ms
56,524 KB
testcase_28 AC 897 ms
56,388 KB
testcase_29 AC 883 ms
56,512 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