結果
問題 | No.2565 はじめてのおつかい |
ユーザー | 21kazu13 |
提出日時 | 2023-12-04 14:56:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 253 ms / 2,000 ms |
コード長 | 1,521 bytes |
コンパイル時間 | 692 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 91,264 KB |
最終ジャッジ日時 | 2024-09-26 23:00:41 |
合計ジャッジ時間 | 12,576 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
64,256 KB |
testcase_01 | AC | 73 ms
64,512 KB |
testcase_02 | AC | 74 ms
64,256 KB |
testcase_03 | AC | 246 ms
91,264 KB |
testcase_04 | AC | 181 ms
90,752 KB |
testcase_05 | AC | 74 ms
64,512 KB |
testcase_06 | AC | 197 ms
80,768 KB |
testcase_07 | AC | 151 ms
79,104 KB |
testcase_08 | AC | 172 ms
81,024 KB |
testcase_09 | AC | 182 ms
80,896 KB |
testcase_10 | AC | 178 ms
80,768 KB |
testcase_11 | AC | 253 ms
84,992 KB |
testcase_12 | AC | 133 ms
78,336 KB |
testcase_13 | AC | 176 ms
80,512 KB |
testcase_14 | AC | 220 ms
82,560 KB |
testcase_15 | AC | 218 ms
82,176 KB |
testcase_16 | AC | 179 ms
86,400 KB |
testcase_17 | AC | 112 ms
77,952 KB |
testcase_18 | AC | 116 ms
80,000 KB |
testcase_19 | AC | 232 ms
83,840 KB |
testcase_20 | AC | 209 ms
84,224 KB |
testcase_21 | AC | 194 ms
83,456 KB |
testcase_22 | AC | 155 ms
81,536 KB |
testcase_23 | AC | 176 ms
81,408 KB |
testcase_24 | AC | 116 ms
78,464 KB |
testcase_25 | AC | 229 ms
84,096 KB |
testcase_26 | AC | 172 ms
81,536 KB |
testcase_27 | AC | 197 ms
84,224 KB |
testcase_28 | AC | 227 ms
83,456 KB |
testcase_29 | AC | 250 ms
85,760 KB |
testcase_30 | AC | 193 ms
84,736 KB |
testcase_31 | AC | 217 ms
84,096 KB |
testcase_32 | AC | 166 ms
81,152 KB |
testcase_33 | AC | 213 ms
84,480 KB |
testcase_34 | AC | 228 ms
83,072 KB |
testcase_35 | AC | 193 ms
85,632 KB |
testcase_36 | AC | 235 ms
84,608 KB |
testcase_37 | AC | 168 ms
81,792 KB |
testcase_38 | AC | 217 ms
83,072 KB |
testcase_39 | AC | 216 ms
82,048 KB |
testcase_40 | AC | 210 ms
84,992 KB |
testcase_41 | AC | 245 ms
86,528 KB |
testcase_42 | AC | 166 ms
80,768 KB |
testcase_43 | AC | 187 ms
82,560 KB |
testcase_44 | AC | 168 ms
80,384 KB |
testcase_45 | AC | 134 ms
78,720 KB |
testcase_46 | AC | 226 ms
82,432 KB |
testcase_47 | AC | 167 ms
79,488 KB |
testcase_48 | AC | 176 ms
80,640 KB |
testcase_49 | AC | 132 ms
78,208 KB |
testcase_50 | AC | 169 ms
80,384 KB |
testcase_51 | AC | 73 ms
64,384 KB |
testcase_52 | AC | 135 ms
78,848 KB |
ソースコード
#!/usr/bin/env python3 import sys from bisect import bisect_left, bisect_right, insort_left, insort_right # type: ignore from collections import Counter, defaultdict, deque # type: ignore from math import gcd, sqrt, ceil, factorial # type: ignore from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge # type: ignore from itertools import accumulate, combinations, permutations, product # type: ignore from string import ascii_lowercase, ascii_uppercase # type: ignore def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode("utf-8").split() def S(): return sys.stdin.buffer.readline().rstrip().decode("utf-8") def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] def SRL(n): return [list(S()) for _ in range(n)] N,M = LI() G = [[] for _ in range(N)] for _ in range(M): u,v = LI() u-=1 v-=1 G[u].append(v) INF = 10**9 def bfs(s): dist = [INF]*N dist[s] = 0 q = deque([s]) while q: v = q.popleft() cur = dist[v] for nex in G[v]: if dist[nex]<INF: continue dist[nex] = cur+1 q.append(nex) return dist d0 = bfs(0) dn2 = bfs(N-2) dn1 = bfs(N-1) ans = min( INF, d0[N-2]+dn2[N-1]+dn1[0], d0[N-1]+dn1[N-2]+dn2[0] ) print(ans if ans<INF else -1)