結果
問題 | No.848 なかよし旅行 |
ユーザー | nephrologist |
提出日時 | 2020-03-24 12:57:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 681 ms / 2,000 ms |
コード長 | 2,101 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 102,456 KB |
最終ジャッジ日時 | 2024-11-08 01:13:27 |
合計ジャッジ時間 | 9,393 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 558 ms
101,812 KB |
testcase_01 | AC | 43 ms
53,888 KB |
testcase_02 | AC | 42 ms
52,864 KB |
testcase_03 | AC | 42 ms
52,992 KB |
testcase_04 | AC | 43 ms
53,632 KB |
testcase_05 | AC | 43 ms
53,120 KB |
testcase_06 | AC | 77 ms
72,192 KB |
testcase_07 | AC | 47 ms
53,504 KB |
testcase_08 | AC | 102 ms
76,536 KB |
testcase_09 | AC | 139 ms
77,464 KB |
testcase_10 | AC | 110 ms
76,452 KB |
testcase_11 | AC | 323 ms
83,712 KB |
testcase_12 | AC | 389 ms
86,416 KB |
testcase_13 | AC | 479 ms
90,604 KB |
testcase_14 | AC | 263 ms
79,348 KB |
testcase_15 | AC | 460 ms
90,076 KB |
testcase_16 | AC | 681 ms
102,456 KB |
testcase_17 | AC | 458 ms
92,488 KB |
testcase_18 | AC | 321 ms
82,596 KB |
testcase_19 | AC | 318 ms
81,500 KB |
testcase_20 | AC | 146 ms
77,668 KB |
testcase_21 | AC | 523 ms
96,012 KB |
testcase_22 | AC | 494 ms
100,852 KB |
testcase_23 | AC | 211 ms
76,984 KB |
testcase_24 | AC | 43 ms
52,608 KB |
testcase_25 | AC | 629 ms
97,728 KB |
testcase_26 | AC | 43 ms
52,480 KB |
testcase_27 | AC | 42 ms
52,480 KB |
testcase_28 | AC | 42 ms
52,992 KB |
testcase_29 | AC | 41 ms
53,120 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)