結果

問題 No.2565 はじめてのおつかい
ユーザー ゼットゼット
提出日時 2023-12-21 00:25:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 768 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 89,976 KB
最終ジャッジ日時 2023-12-21 00:25:24
合計ジャッジ時間 11,331 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,608 KB
testcase_01 WA -
testcase_02 AC 40 ms
55,608 KB
testcase_03 AC 226 ms
89,976 KB
testcase_04 AC 162 ms
89,976 KB
testcase_05 WA -
testcase_06 AC 176 ms
79,496 KB
testcase_07 AC 127 ms
77,808 KB
testcase_08 AC 146 ms
78,980 KB
testcase_09 AC 158 ms
78,960 KB
testcase_10 AC 151 ms
79,504 KB
testcase_11 AC 231 ms
84,060 KB
testcase_12 AC 108 ms
77,168 KB
testcase_13 AC 142 ms
78,064 KB
testcase_14 AC 193 ms
82,208 KB
testcase_15 AC 187 ms
81,256 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 197 ms
81,648 KB
testcase_47 AC 149 ms
78,704 KB
testcase_48 AC 155 ms
79,096 KB
testcase_49 AC 110 ms
77,168 KB
testcase_50 AC 152 ms
78,192 KB
testcase_51 AC 41 ms
55,608 KB
testcase_52 AC 123 ms
76,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
from collections import deque
S=deque()
dist=[10**10]*N
dist[0]=0
S.append(0)
while S:
  x=S.popleft()
  for y in G[x]:
    if dist[y]<10**8:
      continue
    dist[y]=dist[x]+1
    S.append(y)
L1=[10**10]*N
L1[N-1]=0
S=deque()
S.append(N-1)
while S:
  x=S.popleft()
  for y in G[x]:
    if L1[y]<10**8:
      continue
    L1[y]=L1[x]+1
    S.append(y)
L2=[10**10]*N
L2[N-2]=0
S=deque()
S.append(N-2)
while S:
  x=S.popleft()
  for y in G[x]:
    if L2[y]<10**8:
      continue
    L2[y]=L2[x]+1
    S.append(y)
result=10**10
ans=dist[N-1]+L1[N-2]+L2[0]
result=min(result,ans)
ans=dist[N-2]+L2[N-1]+L1[0]
result=min(result,ans)
print(result)
0