結果
問題 | No.2565 はじめてのおつかい |
ユーザー | moharan627 |
提出日時 | 2023-12-02 15:50:50 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 468 ms / 2,000 ms |
コード長 | 1,715 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 81,828 KB |
実行使用メモリ | 136,252 KB |
最終ジャッジ日時 | 2023-12-02 15:51:09 |
合計ジャッジ時間 | 13,470 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
55,604 KB |
testcase_01 | AC | 38 ms
55,604 KB |
testcase_02 | AC | 39 ms
55,604 KB |
testcase_03 | AC | 468 ms
136,244 KB |
testcase_04 | AC | 226 ms
136,252 KB |
testcase_05 | AC | 39 ms
55,604 KB |
testcase_06 | AC | 339 ms
97,760 KB |
testcase_07 | AC | 190 ms
87,664 KB |
testcase_08 | AC | 219 ms
89,396 KB |
testcase_09 | AC | 260 ms
94,876 KB |
testcase_10 | AC | 270 ms
91,460 KB |
testcase_11 | AC | 433 ms
113,840 KB |
testcase_12 | AC | 131 ms
83,520 KB |
testcase_13 | AC | 230 ms
90,316 KB |
testcase_14 | AC | 366 ms
102,164 KB |
testcase_15 | AC | 329 ms
100,536 KB |
testcase_16 | AC | 187 ms
112,796 KB |
testcase_17 | AC | 74 ms
81,860 KB |
testcase_18 | AC | 80 ms
87,308 KB |
testcase_19 | AC | 332 ms
109,552 KB |
testcase_20 | AC | 316 ms
105,972 KB |
testcase_21 | AC | 306 ms
106,020 KB |
testcase_22 | AC | 117 ms
93,172 KB |
testcase_23 | AC | 239 ms
96,340 KB |
testcase_24 | AC | 55 ms
73,380 KB |
testcase_25 | AC | 304 ms
106,328 KB |
testcase_26 | AC | 226 ms
94,892 KB |
testcase_27 | AC | 166 ms
104,164 KB |
testcase_28 | AC | 341 ms
107,536 KB |
testcase_29 | AC | 348 ms
116,112 KB |
testcase_30 | AC | 176 ms
105,784 KB |
testcase_31 | AC | 316 ms
107,036 KB |
testcase_32 | AC | 136 ms
92,004 KB |
testcase_33 | AC | 173 ms
104,908 KB |
testcase_34 | AC | 324 ms
104,204 KB |
testcase_35 | AC | 213 ms
114,888 KB |
testcase_36 | AC | 326 ms
109,116 KB |
testcase_37 | AC | 251 ms
95,536 KB |
testcase_38 | AC | 167 ms
100,424 KB |
testcase_39 | AC | 329 ms
99,788 KB |
testcase_40 | AC | 208 ms
113,012 KB |
testcase_41 | AC | 324 ms
118,380 KB |
testcase_42 | AC | 232 ms
94,300 KB |
testcase_43 | AC | 158 ms
99,560 KB |
testcase_44 | AC | 185 ms
89,652 KB |
testcase_45 | AC | 74 ms
82,160 KB |
testcase_46 | AC | 361 ms
103,092 KB |
testcase_47 | AC | 233 ms
92,648 KB |
testcase_48 | AC | 247 ms
90,588 KB |
testcase_49 | AC | 129 ms
82,880 KB |
testcase_50 | AC | 239 ms
95,264 KB |
testcase_51 | AC | 41 ms
55,604 KB |
testcase_52 | AC | 121 ms
88,116 KB |
ソースコード
import sys #sys.setrecursionlimit(10 ** 6) INF = float('inf') MOD = 10**9 + 7 MOD2 = 998244353 from collections import defaultdict def ceil(A,B): return -(-A//B) import heapq def dijkstra(edges: "List[List[(cost, to)]]", start_node: int) -> list: hq = [] heapq.heapify(hq) # Set start info dist = [INF] * len(edges) heapq.heappush(hq, (0, start_node)) dist[start_node] = 0 # dijkstra while hq: # ------------------------------------------- タイミング1 min_cost, now = heapq.heappop(hq) # ------------------------------------------- タイミング2 if min_cost > dist[now]: continue for cost, next in edges[now]: if dist[next] > dist[now] + cost: dist[next] = dist[now] + cost heapq.heappush(hq, (dist[next], next)) # --------------------------------------- タイミング3 return dist def solve(): def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LC(): return list(sys.stdin.readline().rstrip()) def IC(): return [int(c) for c in sys.stdin.readline().rstrip()] def MI(): return map(int, sys.stdin.readline().split()) N,M = MI() Edge = [[] for _ in range(4*N)] for i in range(M): U,V = MI() U-=1 V-=1 for i in range(4): Edge[i*N+U].append((1,i*N+V)) Edge[N-2].append((0,2*N-2)) Edge[N-1].append((0,3*N-1)) Edge[2*N-1].append((0,4*N-1)) Edge[3*N-2].append((0,4*N -2)) Dist = dijkstra(Edge,0) #print(Dist) if(Dist[3*N]==INF): print(-1) else: print(Dist[3*N]) return solve()