結果

問題 No.1565 Union
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-06-26 13:10:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 100,184 KB
最終ジャッジ日時 2024-05-25 05:23:19
合計ジャッジ時間 8,335 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,212 KB
testcase_01 AC 40 ms
55,208 KB
testcase_02 AC 40 ms
55,008 KB
testcase_03 AC 41 ms
54,420 KB
testcase_04 AC 41 ms
53,808 KB
testcase_05 AC 41 ms
54,184 KB
testcase_06 AC 41 ms
54,848 KB
testcase_07 AC 42 ms
55,024 KB
testcase_08 AC 42 ms
54,856 KB
testcase_09 AC 42 ms
54,756 KB
testcase_10 AC 165 ms
81,220 KB
testcase_11 AC 275 ms
93,512 KB
testcase_12 AC 249 ms
85,896 KB
testcase_13 AC 132 ms
80,876 KB
testcase_14 AC 327 ms
90,464 KB
testcase_15 AC 454 ms
98,672 KB
testcase_16 AC 352 ms
98,520 KB
testcase_17 AC 459 ms
98,764 KB
testcase_18 AC 429 ms
98,672 KB
testcase_19 AC 456 ms
99,408 KB
testcase_20 AC 220 ms
99,564 KB
testcase_21 AC 225 ms
99,628 KB
testcase_22 AC 223 ms
100,060 KB
testcase_23 AC 225 ms
100,184 KB
testcase_24 AC 224 ms
99,856 KB
testcase_25 AC 239 ms
100,184 KB
testcase_26 AC 236 ms
99,572 KB
testcase_27 AC 236 ms
99,716 KB
testcase_28 AC 238 ms
99,832 KB
testcase_29 AC 235 ms
99,692 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