結果

問題 No.1565 Union
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-06-26 14:53:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 456 ms / 2,000 ms
コード長 438 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 100,404 KB
最終ジャッジ日時 2023-12-28 11:47:59
合計ジャッジ時間 8,642 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,332 KB
testcase_01 AC 40 ms
53,332 KB
testcase_02 AC 40 ms
55,484 KB
testcase_03 AC 38 ms
55,484 KB
testcase_04 AC 38 ms
53,332 KB
testcase_05 AC 39 ms
55,484 KB
testcase_06 AC 39 ms
55,484 KB
testcase_07 AC 40 ms
55,484 KB
testcase_08 AC 38 ms
53,332 KB
testcase_09 AC 39 ms
55,484 KB
testcase_10 AC 186 ms
83,732 KB
testcase_11 AC 277 ms
93,488 KB
testcase_12 AC 260 ms
86,360 KB
testcase_13 AC 139 ms
80,900 KB
testcase_14 AC 335 ms
91,116 KB
testcase_15 AC 456 ms
100,404 KB
testcase_16 AC 372 ms
99,124 KB
testcase_17 AC 444 ms
99,892 KB
testcase_18 AC 433 ms
99,764 KB
testcase_19 AC 450 ms
100,404 KB
testcase_20 AC 252 ms
100,276 KB
testcase_21 AC 256 ms
100,276 KB
testcase_22 AC 259 ms
100,276 KB
testcase_23 AC 264 ms
100,276 KB
testcase_24 AC 256 ms
100,276 KB
testcase_25 AC 271 ms
100,276 KB
testcase_26 AC 269 ms
100,276 KB
testcase_27 AC 269 ms
100,276 KB
testcase_28 AC 272 ms
100,276 KB
testcase_29 AC 267 ms
100,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

dis = [n+1]*n
dis[0] = 0
q = deque([0])
while q:
    now = q.popleft()
    for nex in e[now]:
        if dis[nex] > dis[now]+1:
            q.append(nex)
            dis[nex] = dis[now]+1
if dis[-1] == n+1:
    print(-1)
else:
    print(dis[-1])
0