結果

問題 No.848 なかよし旅行
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-10-30 15:01:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 76,492 KB
最終ジャッジ日時 2023-10-12 23:46:10
合計ジャッジ時間 17,944 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,378 ms
55,028 KB
testcase_01 AC 202 ms
43,016 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 199 ms
43,220 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 200 ms
43,152 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 601 ms
49,780 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 221 ms
44,196 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 200 ms
43,056 KB
testcase_25 WA -
testcase_26 AC 202 ms
43,120 KB
testcase_27 AC 201 ms
43,048 KB
testcase_28 AC 197 ms
43,072 KB
testcase_29 AC 199 ms
76,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import lil_matrix

N, M, P, Q, T = map(int, input().split())
P -= 1
Q -= 1

edges = lil_matrix((N, N), dtype=int)

for _ in range(M):
    fr, to, cost = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr, to] = cost

minDistS = list(map(int, shortest_path(edges.tocsr(), directed=False, indices=0)))
minDistP = list(map(int, shortest_path(edges.tocsr(), directed=False, indices=P)))
minDistQ = list(map(int, shortest_path(edges.tocsr(), directed=False, indices=Q)))

ans = -1

if minDistS[P] + minDistP[Q] + minDistQ[0] <= T or minDistS[Q] + minDistQ[P] + minDistQ[0] <= T:
    ans = T

for mid in range(N):
    time = minDistS[mid] * 2 + max(minDistP[mid], minDistQ[mid]) * 2
    if time <= T:
        ans = max(ans, (T - time) + minDistS[mid] * 2)

print(ans)
0