結果

問題 No.2565 はじめてのおつかい
ユーザー KoiKoi
提出日時 2023-12-02 14:50:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 125,208 KB
最終ジャッジ日時 2023-12-02 14:50:57
合計ジャッジ時間 13,046 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,476 KB
testcase_01 AC 45 ms
55,476 KB
testcase_02 AC 42 ms
55,476 KB
testcase_03 AC 425 ms
125,208 KB
testcase_04 AC 239 ms
125,092 KB
testcase_05 AC 40 ms
55,476 KB
testcase_06 AC 226 ms
87,484 KB
testcase_07 AC 149 ms
81,844 KB
testcase_08 AC 159 ms
85,164 KB
testcase_09 AC 206 ms
86,100 KB
testcase_10 AC 193 ms
85,724 KB
testcase_11 AC 372 ms
103,436 KB
testcase_12 AC 118 ms
78,732 KB
testcase_13 AC 167 ms
84,348 KB
testcase_14 AC 256 ms
93,948 KB
testcase_15 AC 278 ms
91,420 KB
testcase_16 AC 239 ms
111,508 KB
testcase_17 AC 99 ms
79,880 KB
testcase_18 AC 110 ms
85,364 KB
testcase_19 AC 284 ms
100,556 KB
testcase_20 AC 264 ms
98,272 KB
testcase_21 AC 268 ms
98,560 KB
testcase_22 AC 150 ms
89,324 KB
testcase_23 AC 181 ms
89,012 KB
testcase_24 AC 92 ms
78,712 KB
testcase_25 AC 262 ms
99,508 KB
testcase_26 AC 180 ms
87,860 KB
testcase_27 AC 234 ms
98,756 KB
testcase_28 AC 272 ms
99,064 KB
testcase_29 AC 329 ms
107,244 KB
testcase_30 AC 238 ms
103,444 KB
testcase_31 AC 276 ms
99,892 KB
testcase_32 AC 158 ms
88,032 KB
testcase_33 AC 227 ms
99,624 KB
testcase_34 AC 254 ms
96,292 KB
testcase_35 AC 256 ms
107,164 KB
testcase_36 AC 284 ms
102,296 KB
testcase_37 AC 180 ms
88,716 KB
testcase_38 AC 211 ms
94,252 KB
testcase_39 AC 249 ms
91,976 KB
testcase_40 AC 280 ms
105,296 KB
testcase_41 AC 314 ms
107,456 KB
testcase_42 AC 181 ms
87,016 KB
testcase_43 AC 201 ms
93,268 KB
testcase_44 AC 155 ms
85,028 KB
testcase_45 AC 101 ms
80,168 KB
testcase_46 AC 274 ms
93,504 KB
testcase_47 AC 175 ms
84,820 KB
testcase_48 AC 181 ms
84,488 KB
testcase_49 AC 114 ms
78,860 KB
testcase_50 AC 184 ms
83,828 KB
testcase_51 AC 41 ms
55,476 KB
testcase_52 AC 132 ms
79,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict,deque
N,M=map(int,input().split())
G=[[] for _ in range(4*N+1)]
#Nで割った余りが
#0 ->F,F
#1 -> T,F
#2 -> F,T
#3 -> T,T
for i in range(M):
    u,v=map(int,input().split())
    G[u].append(v)
    G[N+u].append(N+v)
    G[2*N+u].append(2*N+v)
    G[3*N+u].append(3*N+v)
G[N-1].append(N+N-1)
G[2*N+N-1].append(3*N+N-1)
G[N].append(2*N+N)
G[N+N].append(2*N+N+N)
dis=[-1 for _ in range(4*N+1)]
que=deque([1])
seen=[False]*(4*N+1)
seen[1]=True
dis[1]=0
while len(que):
    p=que.popleft()
    for q in G[p]:
        if(not seen[q]):
            seen[q]=True
            dis[q]=dis[p]+1
            que.append(q)
print(max(dis[3*N+1]-2,-1))
0