結果

問題 No.1565 Union
ユーザー PSL24251284PSL24251284
提出日時 2021-06-26 16:47:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 460 ms / 2,000 ms
コード長 419 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 99,512 KB
最終ジャッジ日時 2023-12-25 09:49:45
合計ジャッジ時間 8,887 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 40 ms
55,612 KB
testcase_03 AC 39 ms
55,612 KB
testcase_04 AC 39 ms
53,460 KB
testcase_05 AC 41 ms
55,612 KB
testcase_06 AC 40 ms
55,612 KB
testcase_07 AC 42 ms
55,612 KB
testcase_08 AC 41 ms
53,460 KB
testcase_09 AC 40 ms
55,612 KB
testcase_10 AC 164 ms
80,780 KB
testcase_11 AC 267 ms
93,244 KB
testcase_12 AC 243 ms
85,448 KB
testcase_13 AC 132 ms
80,676 KB
testcase_14 AC 326 ms
90,236 KB
testcase_15 AC 460 ms
98,616 KB
testcase_16 AC 350 ms
98,360 KB
testcase_17 AC 447 ms
98,616 KB
testcase_18 AC 425 ms
98,616 KB
testcase_19 AC 439 ms
98,744 KB
testcase_20 AC 215 ms
99,512 KB
testcase_21 AC 220 ms
99,512 KB
testcase_22 AC 224 ms
99,512 KB
testcase_23 AC 220 ms
99,512 KB
testcase_24 AC 219 ms
99,512 KB
testcase_25 AC 245 ms
99,512 KB
testcase_26 AC 234 ms
99,512 KB
testcase_27 AC 234 ms
99,508 KB
testcase_28 AC 234 ms
99,512 KB
testcase_29 AC 232 ms
99,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,M = map(int,input().split())
E = [[] for i in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
q = deque()
q.append(0)
dp = [0]*N
while q:
    x = q.pop()
    for y in E[x]:
        if y != 0 and dp[y] == 0:
            dp[y] = dp[x]+1
            q.appendleft(y)
if dp[-1] == 0:
    ans = -1
else:
    ans = dp[-1]
print(ans)
0