結果

問題 No.1565 Union
ユーザー brthyyjpbrthyyjp
提出日時 2021-07-12 20:01:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 102,692 KB
最終ジャッジ日時 2024-05-03 22:49:35
合計ジャッジ時間 6,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,888 KB
testcase_01 AC 44 ms
53,504 KB
testcase_02 AC 42 ms
53,632 KB
testcase_03 AC 44 ms
53,888 KB
testcase_04 AC 42 ms
53,632 KB
testcase_05 AC 42 ms
53,504 KB
testcase_06 AC 41 ms
53,760 KB
testcase_07 AC 44 ms
53,888 KB
testcase_08 AC 42 ms
53,888 KB
testcase_09 AC 42 ms
53,504 KB
testcase_10 AC 101 ms
80,832 KB
testcase_11 AC 182 ms
93,808 KB
testcase_12 AC 157 ms
84,396 KB
testcase_13 AC 95 ms
80,808 KB
testcase_14 AC 190 ms
90,668 KB
testcase_15 AC 295 ms
101,016 KB
testcase_16 AC 224 ms
100,756 KB
testcase_17 AC 284 ms
101,260 KB
testcase_18 AC 257 ms
100,880 KB
testcase_19 AC 282 ms
100,752 KB
testcase_20 AC 135 ms
102,292 KB
testcase_21 AC 138 ms
102,568 KB
testcase_22 AC 141 ms
102,560 KB
testcase_23 AC 151 ms
102,304 KB
testcase_24 AC 147 ms
102,300 KB
testcase_25 AC 158 ms
102,692 KB
testcase_26 AC 151 ms
102,180 KB
testcase_27 AC 157 ms
102,432 KB
testcase_28 AC 157 ms
102,568 KB
testcase_29 AC 152 ms
102,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)

from collections import deque
q = deque([])
q.append(0)
dist = [-1]*n
dist[0] = 0
while q:
    v = q.popleft()
    for u in g[v]:
        if dist[u] == -1:
            q.append(u)
            dist[u] = dist[v]+1
if dist[n-1] == -1:
    print(-1)
else:
    print(dist[n-1])
0