結果
問題 | No.848 なかよし旅行 |
ユーザー | terasa |
提出日時 | 2022-06-10 13:34:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 531 ms / 2,000 ms |
コード長 | 1,899 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 104,996 KB |
最終ジャッジ日時 | 2024-09-21 05:45:30 |
合計ジャッジ時間 | 6,872 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 531 ms
104,996 KB |
testcase_01 | AC | 47 ms
56,504 KB |
testcase_02 | AC | 44 ms
55,892 KB |
testcase_03 | AC | 46 ms
56,764 KB |
testcase_04 | AC | 45 ms
55,808 KB |
testcase_05 | AC | 46 ms
55,588 KB |
testcase_06 | AC | 58 ms
66,596 KB |
testcase_07 | AC | 45 ms
56,184 KB |
testcase_08 | AC | 91 ms
77,816 KB |
testcase_09 | AC | 101 ms
77,272 KB |
testcase_10 | AC | 93 ms
77,380 KB |
testcase_11 | AC | 184 ms
80,132 KB |
testcase_12 | AC | 201 ms
81,068 KB |
testcase_13 | AC | 234 ms
82,704 KB |
testcase_14 | AC | 166 ms
78,780 KB |
testcase_15 | AC | 224 ms
82,332 KB |
testcase_16 | AC | 285 ms
87,472 KB |
testcase_17 | AC | 225 ms
83,404 KB |
testcase_18 | AC | 184 ms
80,340 KB |
testcase_19 | AC | 188 ms
79,272 KB |
testcase_20 | AC | 163 ms
77,812 KB |
testcase_21 | AC | 236 ms
84,476 KB |
testcase_22 | AC | 174 ms
86,600 KB |
testcase_23 | AC | 177 ms
78,240 KB |
testcase_24 | AC | 43 ms
56,240 KB |
testcase_25 | AC | 302 ms
87,452 KB |
testcase_26 | AC | 44 ms
55,532 KB |
testcase_27 | AC | 45 ms
56,408 KB |
testcase_28 | AC | 45 ms
56,292 KB |
testcase_29 | AC | 45 ms
54,932 KB |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class Dijkstra: def __init__(self, N, E, inf=1 << 50): self.N = N self.E = E self.inf = inf def cost_from(self, s): C = [self.inf] * self.N C[s] = 0 h = [(0, s)] visited = set() while len(h) > 0: _, v = heapq.heappop(h) if v in visited: continue visited.add(v) for c, dest in self.E[v]: if C[dest] > C[v] + c: C[dest] = C[v] + c heapq.heappush(h, (C[dest], dest)) return C N, M, P, Q, T = map(int, input().split()) P -= 1 Q -= 1 E = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 E[a].append((c, b)) E[b].append((c, a)) solver = Dijkstra(N, E) C0 = solver.cost_from(0) Cp = solver.cost_from(P) Cq = solver.cost_from(Q) if C0[P] + Cp[Q] + Cq[0] <= T: print(T) exit() ans = -1 for i in range(N): for j in range(N): t = C0[i] + max(Cp[i] + Cp[j], Cq[i] + Cq[j]) + C0[j] if t <= T: ans = max(ans, C0[i] + C0[j] + (T - t)) print(ans)