結果
問題 | No.848 なかよし旅行 |
ユーザー | roaris |
提出日時 | 2019-07-26 16:43:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 642 ms / 2,000 ms |
コード長 | 1,589 bytes |
コンパイル時間 | 325 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 104,348 KB |
最終ジャッジ日時 | 2024-11-08 01:09:08 |
合計ジャッジ時間 | 8,682 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 642 ms
104,348 KB |
testcase_01 | AC | 66 ms
64,128 KB |
testcase_02 | AC | 49 ms
54,272 KB |
testcase_03 | AC | 52 ms
54,784 KB |
testcase_04 | AC | 51 ms
54,784 KB |
testcase_05 | AC | 51 ms
55,040 KB |
testcase_06 | AC | 73 ms
65,920 KB |
testcase_07 | AC | 58 ms
61,184 KB |
testcase_08 | AC | 125 ms
76,928 KB |
testcase_09 | AC | 149 ms
77,952 KB |
testcase_10 | AC | 134 ms
77,696 KB |
testcase_11 | AC | 315 ms
81,744 KB |
testcase_12 | AC | 336 ms
83,344 KB |
testcase_13 | AC | 362 ms
84,724 KB |
testcase_14 | AC | 301 ms
80,832 KB |
testcase_15 | AC | 364 ms
84,072 KB |
testcase_16 | AC | 439 ms
89,560 KB |
testcase_17 | AC | 363 ms
85,548 KB |
testcase_18 | AC | 327 ms
81,976 KB |
testcase_19 | AC | 329 ms
82,116 KB |
testcase_20 | AC | 254 ms
79,532 KB |
testcase_21 | AC | 393 ms
86,456 KB |
testcase_22 | AC | 315 ms
88,116 KB |
testcase_23 | AC | 252 ms
79,896 KB |
testcase_24 | AC | 49 ms
53,888 KB |
testcase_25 | AC | 451 ms
89,800 KB |
testcase_26 | AC | 50 ms
54,272 KB |
testcase_27 | AC | 50 ms
54,144 KB |
testcase_28 | AC | 50 ms
54,784 KB |
testcase_29 | AC | 51 ms
54,144 KB |
ソースコード
from heapq import heappush, heappop from collections import defaultdict def dijkstra(start): distance = [10 ** 18 for _ in range(N)] distance[start] = 0 priority_queue = [] for i in range(N): heappush(priority_queue, (distance[i], i)) while len(priority_queue) > 0: current_dist, current_node = heappop(priority_queue) if distance[current_node] < current_dist: continue for next_node, w in adj_dict[current_node]: if distance[next_node] > distance[current_node] + w: distance[next_node] = distance[current_node] + w heappush(priority_queue, (distance[next_node], next_node)) return distance N, M, P, Q, T = map(int, input().split()) adj_dict = defaultdict(list) for _ in range(M): a_i, b_i, c_i = map(int, input().split()) adj_dict[a_i-1].append((b_i-1, c_i)) adj_dict[b_i-1].append((a_i-1, c_i)) distance_from0 = dijkstra(0) distance_fromP = dijkstra(P-1) distance_fromQ = dijkstra(Q-1) ans = -10 ** 18 if distance_from0[P-1] + distance_fromP[Q-1] + distance_fromQ[0] <= T: print(T) exit() for m1 in range(N): for m2 in range(m1, N): if distance_from0[m1] + max(distance_fromP[m1]+distance_fromP[m2], distance_fromQ[m1]+distance_fromQ[m2]) + distance_from0[m2] <= T: ans = max(ans, distance_from0[m1] + distance_from0[m2] + T - (distance_from0[m1] + max(distance_fromP[m1]+distance_fromP[m2], distance_fromQ[m1]+distance_fromQ[m2]) + distance_from0[m2])) if ans == -10 ** 18: print(-1) else: print(ans)