結果
問題 | No.848 なかよし旅行 |
ユーザー | Coki628 |
提出日時 | 2020-08-13 11:19:08 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,767 bytes |
コンパイル時間 | 559 ms |
コンパイル使用メモリ | 82,952 KB |
実行使用メモリ | 94,560 KB |
最終ジャッジ日時 | 2024-10-09 19:06:33 |
合計ジャッジ時間 | 6,176 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 326 ms
94,560 KB |
testcase_01 | AC | 40 ms
54,504 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 41 ms
53,852 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 42 ms
54,588 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 169 ms
82,216 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 98 ms
77,640 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 40 ms
53,296 KB |
testcase_25 | WA | - |
testcase_26 | AC | 40 ms
53,860 KB |
testcase_27 | AC | 39 ms
53,520 KB |
testcase_28 | AC | 38 ms
54,340 KB |
testcase_29 | AC | 39 ms
53,676 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): cost = (dist1[i] + max(dist2[i], dist3[i])) * 2 have = t - cost if have >= 0: ans = max(ans, have + dist1[i]*2) cost = (dist1[i] + dist2[i] + dist3[i]) * 2 have = t - cost if have >= 0: ans = max(ans, t) print(ans)