結果

問題 No.1565 Union
ユーザー 👑 Kazun
提出日時 2021-06-27 22:11:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 377 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 100,540 KB
最終ジャッジ日時 2025-01-02 02:51:02
合計ジャッジ時間 7,658 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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