結果

問題 No.1565 Union
ユーザー 👑 KazunKazun
提出日時 2021-06-27 22:11:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 377 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 100,352 KB
最終ジャッジ日時 2024-05-01 21:15:54
合計ジャッジ時間 6,660 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,248 KB
testcase_01 AC 41 ms
53,248 KB
testcase_02 AC 42 ms
53,376 KB
testcase_03 AC 41 ms
53,504 KB
testcase_04 AC 41 ms
53,504 KB
testcase_05 AC 41 ms
53,504 KB
testcase_06 AC 41 ms
53,376 KB
testcase_07 AC 42 ms
53,504 KB
testcase_08 AC 40 ms
53,504 KB
testcase_09 AC 40 ms
53,504 KB
testcase_10 AC 112 ms
80,512 KB
testcase_11 AC 179 ms
92,544 KB
testcase_12 AC 164 ms
85,248 KB
testcase_13 AC 98 ms
79,872 KB
testcase_14 AC 201 ms
89,856 KB
testcase_15 AC 301 ms
98,688 KB
testcase_16 AC 220 ms
98,176 KB
testcase_17 AC 279 ms
98,688 KB
testcase_18 AC 271 ms
98,688 KB
testcase_19 AC 290 ms
99,072 KB
testcase_20 AC 158 ms
100,096 KB
testcase_21 AC 157 ms
99,840 KB
testcase_22 AC 154 ms
100,352 KB
testcase_23 AC 158 ms
99,840 KB
testcase_24 AC 163 ms
100,224 KB
testcase_25 AC 168 ms
100,096 KB
testcase_26 AC 166 ms
100,224 KB
testcase_27 AC 172 ms
99,840 KB
testcase_28 AC 173 ms
100,224 KB
testcase_29 AC 169 ms
99,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input=sys.stdin.readline

N,M=map(int,input().split())
E=[[] for _ in range(N+1)]
for _ in range(M):
    a,b=map(int,input().split())
    E[a].append(b)
    E[b].append(a)

X=[-1]*(N+1); X[1]=0
Q=deque([1])
while Q:
    x=Q.popleft()

    for y in E[x]:
        if X[y]==-1:
            X[y]=X[x]+1
            Q.append(y)

print(X[N])
0