結果
問題 | No.2569 はじめてのおつかいHard |
ユーザー | mymelochan |
提出日時 | 2023-12-02 16:22:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 671 ms / 2,000 ms |
コード長 | 1,315 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 120,552 KB |
最終ジャッジ日時 | 2023-12-02 16:22:42 |
合計ジャッジ時間 | 5,659 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 230 ms
93,816 KB |
testcase_01 | AC | 246 ms
93,176 KB |
testcase_02 | AC | 233 ms
93,176 KB |
testcase_03 | AC | 229 ms
93,432 KB |
testcase_04 | AC | 226 ms
93,176 KB |
testcase_05 | AC | 627 ms
120,312 KB |
testcase_06 | AC | 671 ms
106,856 KB |
testcase_07 | AC | 406 ms
118,744 KB |
testcase_08 | AC | 565 ms
120,552 KB |
testcase_09 | AC | 444 ms
102,180 KB |
testcase_10 | AC | 39 ms
55,724 KB |
testcase_11 | AC | 38 ms
55,724 KB |
ソースコード
############################################################# import sys sys.setrecursionlimit(10**7) from heapq import heappop,heappush from collections import deque,defaultdict,Counter from bisect import bisect_left, bisect_right from itertools import product,combinations,permutations from math import sin,cos #from math import isqrt #DO NOT USE PyPy ipt = sys.stdin.readline iin = lambda :int(ipt()) lmin = lambda :list(map(int,ipt().split())) INF = 1<<60 def dijkstra_r(g,s,n): cost = [INF] * n hq = [] heappush(hq,(0,s)) while hq: c1,v1 = heappop(hq) if cost[v1] < c1: continue cost[v1] = c1 for v2,c2 in g[v1]: if c1+c2 < cost[v2]: cost[v2] = c1+c2 heappush(hq,(cost[v2],v2)) return cost ############################################################# N,M = lmin() G = [[] for _ in range(N)] RG = [[] for _ in range(N)] for _ in range(M): a,b,t = lmin() G[a-1].append((b-1,t)) RG[b-1].append((a-1,t)) cost2 = dijkstra_r(G,N-2,N) cost2r = dijkstra_r(RG,N-2,N) cost3 = dijkstra_r(G,N-1,N) cost3r = dijkstra_r(RG,N-1,N) for i in range(N-2): ans = min(cost2r[i]+cost2[N-1]+cost3[i],cost3r[i]+cost3[N-2]+cost2[i]) if ans >= INF: print(-1) else: print(ans)