結果

問題 No.1565 Union
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-06-26 13:10:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 99,288 KB
最終ジャッジ日時 2023-12-29 16:52:16
合計ジャッジ時間 7,279 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 41 ms
53,460 KB
testcase_03 AC 39 ms
55,612 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
55,612 KB
testcase_06 AC 39 ms
55,608 KB
testcase_07 AC 38 ms
55,604 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 40 ms
55,608 KB
testcase_10 AC 151 ms
80,652 KB
testcase_11 AC 233 ms
93,288 KB
testcase_12 AC 217 ms
85,328 KB
testcase_13 AC 121 ms
80,424 KB
testcase_14 AC 266 ms
89,884 KB
testcase_15 AC 376 ms
98,392 KB
testcase_16 AC 296 ms
98,136 KB
testcase_17 AC 367 ms
98,392 KB
testcase_18 AC 357 ms
98,384 KB
testcase_19 AC 362 ms
98,512 KB
testcase_20 AC 209 ms
99,288 KB
testcase_21 AC 211 ms
99,288 KB
testcase_22 AC 215 ms
99,288 KB
testcase_23 AC 214 ms
99,288 KB
testcase_24 AC 225 ms
99,288 KB
testcase_25 AC 230 ms
99,288 KB
testcase_26 AC 223 ms
99,288 KB
testcase_27 AC 222 ms
99,288 KB
testcase_28 AC 230 ms
99,288 KB
testcase_29 AC 218 ms
99,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
G = [[] for i in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1; b -= 1
    G[a].append(b)
    G[b].append(a)
from collections import deque
Q = deque([0])
dist = [-1] * n
dist[0] = 0
while Q:
    now = Q.popleft()
    for nex in G[now]:
        if dist[nex] == -1:
            dist[nex] = dist[now] + 1
            Q.append(nex)
print(dist[-1])
0