結果

問題 No.2565 はじめてのおつかい
ユーザー hirayuu_ychirayuu_yc
提出日時 2023-12-02 14:35:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 625 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 212,280 KB
最終ジャッジ日時 2023-12-02 14:36:10
合計ジャッジ時間 20,848 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
55,476 KB
testcase_01 AC 35 ms
55,476 KB
testcase_02 AC 38 ms
55,476 KB
testcase_03 AC 625 ms
212,280 KB
testcase_04 AC 356 ms
212,280 KB
testcase_05 AC 38 ms
55,476 KB
testcase_06 AC 366 ms
108,988 KB
testcase_07 AC 188 ms
93,476 KB
testcase_08 AC 233 ms
102,076 KB
testcase_09 AC 285 ms
104,356 KB
testcase_10 AC 258 ms
105,032 KB
testcase_11 AC 562 ms
151,688 KB
testcase_12 AC 132 ms
84,124 KB
testcase_13 AC 271 ms
101,540 KB
testcase_14 AC 425 ms
128,860 KB
testcase_15 AC 421 ms
121,756 KB
testcase_16 AC 342 ms
160,632 KB
testcase_17 AC 107 ms
88,612 KB
testcase_18 AC 128 ms
97,496 KB
testcase_19 AC 472 ms
141,872 KB
testcase_20 AC 401 ms
136,216 KB
testcase_21 AC 370 ms
137,504 KB
testcase_22 AC 181 ms
108,080 KB
testcase_23 AC 276 ms
116,900 KB
testcase_24 AC 78 ms
78,388 KB
testcase_25 AC 422 ms
137,900 KB
testcase_26 AC 261 ms
113,024 KB
testcase_27 AC 302 ms
135,508 KB
testcase_28 AC 411 ms
140,060 KB
testcase_29 AC 495 ms
159,296 KB
testcase_30 AC 312 ms
136,840 KB
testcase_31 AC 450 ms
139,564 KB
testcase_32 AC 177 ms
107,404 KB
testcase_33 AC 307 ms
136,176 KB
testcase_34 AC 397 ms
132,068 KB
testcase_35 AC 334 ms
146,796 KB
testcase_36 AC 448 ms
144,364 KB
testcase_37 AC 271 ms
115,352 KB
testcase_38 AC 319 ms
124,904 KB
testcase_39 AC 373 ms
121,640 KB
testcase_40 AC 362 ms
146,104 KB
testcase_41 AC 480 ms
156,664 KB
testcase_42 AC 274 ms
111,340 KB
testcase_43 AC 282 ms
123,728 KB
testcase_44 AC 230 ms
102,456 KB
testcase_45 AC 115 ms
88,484 KB
testcase_46 AC 456 ms
125,220 KB
testcase_47 AC 264 ms
99,236 KB
testcase_48 AC 285 ms
102,316 KB
testcase_49 AC 129 ms
84,380 KB
testcase_50 AC 284 ms
104,632 KB
testcase_51 AC 37 ms
55,476 KB
testcase_52 AC 182 ms
94,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
INF=pow(2,61)-1
N,M=map(int,input().split())
gr=[[set() for i in range(4)] for i in range(N)]
for i in range(M):
    u,v=map(int,input().split())
    for j in range(4):
        if v==N-1:
            gr[u-1][j].add((v-1,j|1))
        elif v==N:
            gr[u-1][j].add((v-1,j|2))
        else:
            gr[u-1][j].add((v-1,j))
pos=deque([(0,0)])
ans=[[INF]*4 for i in range(N)]
ans[0][0]=0
while len(pos)>0:
    a,b=pos.popleft()
    for i,j in gr[a][b]:
        if ans[i][j]>ans[a][b]+1:
            ans[i][j]=ans[a][b]+1
            pos.append((i,j))
if ans[0][3]>=INF:
    print(-1)
else:
    print(ans[0][3])
0