結果
問題 | No.848 なかよし旅行 |
ユーザー | Coki628 |
提出日時 | 2020-08-13 12:15:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 496 ms / 2,000 ms |
コード長 | 1,852 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 94,720 KB |
最終ジャッジ日時 | 2024-11-08 01:18:32 |
合計ジャッジ時間 | 7,047 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 496 ms
94,720 KB |
testcase_01 | AC | 58 ms
61,696 KB |
testcase_02 | AC | 45 ms
52,992 KB |
testcase_03 | AC | 46 ms
53,504 KB |
testcase_04 | AC | 46 ms
53,632 KB |
testcase_05 | AC | 47 ms
53,632 KB |
testcase_06 | AC | 65 ms
64,384 KB |
testcase_07 | AC | 54 ms
60,416 KB |
testcase_08 | AC | 104 ms
76,800 KB |
testcase_09 | AC | 119 ms
77,568 KB |
testcase_10 | AC | 103 ms
77,312 KB |
testcase_11 | AC | 251 ms
80,128 KB |
testcase_12 | AC | 280 ms
81,280 KB |
testcase_13 | AC | 289 ms
82,304 KB |
testcase_14 | AC | 229 ms
78,592 KB |
testcase_15 | AC | 286 ms
82,176 KB |
testcase_16 | AC | 376 ms
87,168 KB |
testcase_17 | AC | 271 ms
83,584 KB |
testcase_18 | AC | 234 ms
79,360 KB |
testcase_19 | AC | 228 ms
79,232 KB |
testcase_20 | AC | 215 ms
77,696 KB |
testcase_21 | AC | 296 ms
85,248 KB |
testcase_22 | AC | 210 ms
86,656 KB |
testcase_23 | AC | 221 ms
77,440 KB |
testcase_24 | AC | 45 ms
53,376 KB |
testcase_25 | AC | 383 ms
86,912 KB |
testcase_26 | AC | 46 ms
53,248 KB |
testcase_27 | AC | 45 ms
52,864 KB |
testcase_28 | AC | 45 ms
52,736 KB |
testcase_29 | AC | 45 ms
53,120 KB |
ソースコード
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 19 MOD = 10 ** 9 + 7 EPS = 10 ** -10 def dijkstra(nodes: list, src: int) -> list: """ ダイクストラ高速化版(隣接リスト(0-indexed), 始点) """ from heapq import heappush, heappop N = len(nodes) res = [INF] * N que = [src] res[src] = 0 while que: cur = heappop(que) dist = cur // N cur %= N if res[cur] < dist: continue for nxt, cost in nodes[cur]: if dist + cost < res[nxt]: res[nxt] = dist + cost heappush(que, (dist+cost)*N+nxt) return res N, M, p, q, t = MAP() p -= 1; q -= 1 nodes = [[] for i in range(N)] for i in range(M): a, b, c = MAP() a -= 1; b -= 1 nodes[a].append((b, c)) nodes[b].append((a, c)) dist1 = dijkstra(nodes, 0) dist2 = dijkstra(nodes, p) dist3 = dijkstra(nodes, q) ans = -1 for i in range(N): for j in range(N): have = t - (dist1[i] + dist1[j] + max(dist2[i] + dist2[j], dist3[i] + dist3[j])) if have >= 0: ans = max(ans, have + dist1[i] + dist1[j]) have = t - (dist1[i] + dist2[i] + dist3[i] + dist1[j] + dist2[j] + dist3[j]) if have >= 0: ans = max(ans, t) print(ans)