結果

問題 No.848 なかよし旅行
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-02 00:21:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 743 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 106,732 KB
最終ジャッジ日時 2024-04-19 21:13:52
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, M, P, Q, T = map(int, input().split())
A, B, C = np.array([input().split() for _ in range(M)], dtype=np.int64).T

G = csr_matrix((C, (A-1, B-1)), shape=(N, N))
path = (dijkstra(G, directed=False) + 0.01).astype(np.int64)

# ぜんぶ2人で回る
t = path[0][P-1] + path[P-1][Q-1] + path[Q-1][0]
if t <= T:
    print(T)
    exit()

ans = 0
same = path[0, :]
toP = path[:, P-1]
toQ = path[:, Q-1]
time = 2 * (same + np.maximum(toP, toQ))
wait = np.maximum(0, T - time)
if (time > T).all():
    print(-1)
    exit()

ans = (2 * same + wait)[time <= T].max()
print(ans)
0