結果
問題 | No.848 なかよし旅行 |
ユーザー | nephrologist |
提出日時 | 2020-03-24 12:56:21 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,101 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 52,212 KB |
最終ジャッジ日時 | 2024-12-31 14:48:00 |
合計ジャッジ時間 | 42,347 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,156 ms
51,504 KB |
testcase_01 | AC | 35 ms
31,872 KB |
testcase_02 | AC | 34 ms
17,828 KB |
testcase_03 | AC | 35 ms
35,488 KB |
testcase_04 | AC | 35 ms
17,696 KB |
testcase_05 | AC | 34 ms
41,324 KB |
testcase_06 | AC | 38 ms
17,696 KB |
testcase_07 | AC | 34 ms
25,472 KB |
testcase_08 | AC | 119 ms
17,960 KB |
testcase_09 | AC | 114 ms
18,084 KB |
testcase_10 | AC | 117 ms
17,952 KB |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | AC | 50 ms
23,808 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 1,589 ms
48,588 KB |
testcase_23 | TLE | - |
testcase_24 | AC | 34 ms
11,008 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 35 ms
11,136 KB |
testcase_27 | AC | 33 ms
11,008 KB |
testcase_28 | AC | 34 ms
11,008 KB |
testcase_29 | AC | 35 ms
52,212 KB |
ソースコード
# 場合分けが甘い。 # 全部一緒と不可能のケースはOK # 最初、途中まで一緒→最後一緒のパターンが甘い。 # 3頂点からの最短距離の組み合わせで行ける。 import sys input = sys.stdin.buffer.readline from heapq import heappush, heappop n, m, p, q, t = map(int, input().split()) graph = [[] for _ in range(n + 1)] for _ in range(m): a, b, c = map(int, input().split()) graph[a].append((c, b)) graph[b].append((c, a)) infi = 10 ** 20 dist = [infi] * (n + 1) used = [False] * (n + 1) edgelist = [] def dijkstra(start, dist): dist[start] = 0 used[start] = True for cost, v in graph[start]: heappush(edgelist, (cost, v)) while edgelist: cost, v = heappop(edgelist) if used[v]: continue used[v] = True dist[v] = min(cost, dist[v]) for cost2, w in graph[v]: if used[w]: continue new_cost = cost2 + cost heappush(edgelist, (new_cost, w)) return dist calculated_dist1 = dijkstra(1, dist) dist_ap = dist[p] dist_aq = dist[q] distp = [infi] * (n + 1) used = [False] * (n + 1) edgelist = [] calculated_distp = dijkstra(p, distp) dist_pq = calculated_distp[q] distq = [infi] * (n + 1) used = [False] * (n + 1) edgelist = [] calculated_distq = dijkstra(q, distq) longer = max(dist_ap, dist_aq) if dist_ap + dist_aq + dist_pq <= t: print(t) elif 2 * longer > t: print(-1) else: ans = 0 for i in range(1, n + 1): for j in range(1, n + 1): total_p = ( calculated_dist1[i] + calculated_distp[i] + calculated_distp[j] + calculated_dist1[j] ) total_q = ( calculated_dist1[i] + calculated_distq[i] + calculated_distq[j] + calculated_dist1[j] ) bigger = max(total_p, total_q) if bigger <= t: ans = max(ans, calculated_dist1[i] + calculated_dist1[j] + t - bigger) print(ans)