結果

問題 No.2565 はじめてのおつかい
ユーザー kemunikukemuniku
提出日時 2023-12-02 15:43:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 467 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 116,232 KB
最終ジャッジ日時 2023-12-02 15:43:52
合計ジャッジ時間 11,211 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 32 ms
53,460 KB
testcase_03 AC 223 ms
114,448 KB
testcase_04 AC 189 ms
114,232 KB
testcase_05 AC 33 ms
53,460 KB
testcase_06 AC 264 ms
99,252 KB
testcase_07 AC 197 ms
87,572 KB
testcase_08 AC 170 ms
90,940 KB
testcase_09 AC 215 ms
93,936 KB
testcase_10 AC 229 ms
97,580 KB
testcase_11 AC 355 ms
116,232 KB
testcase_12 AC 133 ms
77,424 KB
testcase_13 AC 185 ms
90,292 KB
testcase_14 AC 284 ms
107,248 KB
testcase_15 AC 300 ms
104,788 KB
testcase_16 AC 110 ms
83,132 KB
testcase_17 AC 69 ms
76,784 KB
testcase_18 AC 71 ms
77,984 KB
testcase_19 AC 216 ms
98,264 KB
testcase_20 AC 211 ms
97,248 KB
testcase_21 AC 165 ms
89,192 KB
testcase_22 AC 112 ms
78,972 KB
testcase_23 AC 147 ms
88,560 KB
testcase_24 AC 59 ms
73,840 KB
testcase_25 AC 203 ms
101,108 KB
testcase_26 AC 175 ms
91,852 KB
testcase_27 AC 110 ms
80,920 KB
testcase_28 AC 177 ms
89,316 KB
testcase_29 AC 265 ms
101,252 KB
testcase_30 AC 118 ms
81,356 KB
testcase_31 AC 225 ms
97,828 KB
testcase_32 AC 87 ms
78,680 KB
testcase_33 AC 119 ms
81,204 KB
testcase_34 AC 229 ms
96,812 KB
testcase_35 AC 117 ms
82,096 KB
testcase_36 AC 204 ms
99,504 KB
testcase_37 AC 181 ms
90,340 KB
testcase_38 AC 119 ms
80,048 KB
testcase_39 AC 288 ms
105,976 KB
testcase_40 AC 126 ms
81,788 KB
testcase_41 AC 184 ms
93,116 KB
testcase_42 AC 176 ms
89,656 KB
testcase_43 AC 105 ms
79,256 KB
testcase_44 AC 139 ms
84,740 KB
testcase_45 AC 77 ms
76,912 KB
testcase_46 AC 281 ms
104,992 KB
testcase_47 AC 196 ms
85,664 KB
testcase_48 AC 193 ms
92,444 KB
testcase_49 AC 125 ms
77,680 KB
testcase_50 AC 211 ms
85,104 KB
testcase_51 AC 33 ms
53,460 KB
testcase_52 AC 139 ms
77,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
G = [[] for i in range(N)]
for i in range(M):
    u,v = map(int,input().split())
    u-=1
    v-=1
    G[u].append(v)

stack = [(0,False,False,0)]
alr = set()
for i,f1,f2,c in stack:
    if i == 0 and f1 and f2:
        print(c)
        exit()
    for j in G[i]:
        x = (j,f1|(j==N-2),f2|(j==N-1))
        if x not in alr:
            alr.add(x)
            y = (j,f1|(j==N-2),f2|(j==N-1),c+1)
            stack.append(y)
print(-1)
0