結果

問題 No.848 なかよし旅行
ユーザー H3PO4
提出日時 2021-02-24 18:04:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 614 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 109,040 KB
最終ジャッジ日時 2024-09-24 18:51:30
合計ジャッジ時間 39,532 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 WA * 21 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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()

possible = ((way_1 + way_p) * 2 <= T) & ((way_1 + way_q) * 2 <= T)
if not np.any(possible):
    print(-1)
    exit()
time = T - np.maximum(way_p, way_q) * 2
print(time.max())
0