結果
問題 | No.848 なかよし旅行 |
ユーザー | OKCH3COOH |
提出日時 | 2019-10-30 15:11:37 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 858 bytes |
コンパイル時間 | 109 ms |
コンパイル使用メモリ | 10,820 KB |
実行使用メモリ | 54,696 KB |
最終ジャッジ日時 | 2023-10-12 23:48:19 |
合計ジャッジ時間 | 15,175 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 972 ms
54,696 KB |
testcase_01 | AC | 200 ms
42,928 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 203 ms
43,144 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 202 ms
42,956 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 605 ms
49,532 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 229 ms
44,024 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 203 ms
43,140 KB |
testcase_25 | WA | - |
testcase_26 | AC | 203 ms
43,128 KB |
testcase_27 | AC | 202 ms
42,868 KB |
testcase_28 | AC | 202 ms
43,092 KB |
testcase_29 | AC | 203 ms
43,312 KB |
ソースコード
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] + minDistP[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)