結果

問題 No.1565 Union
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-20 13:35:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,188 ms / 2,000 ms
コード長 354 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 51,712 KB
最終ジャッジ日時 2024-04-30 02:09:30
合計ジャッジ時間 20,513 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
10,752 KB
testcase_01 AC 31 ms
10,624 KB
testcase_02 AC 33 ms
10,624 KB
testcase_03 AC 31 ms
10,624 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 31 ms
10,624 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 AC 32 ms
10,752 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 32 ms
10,624 KB
testcase_10 AC 490 ms
21,120 KB
testcase_11 AC 660 ms
35,200 KB
testcase_12 AC 799 ms
28,928 KB
testcase_13 AC 242 ms
17,920 KB
testcase_14 AC 855 ms
33,920 KB
testcase_15 AC 1,183 ms
44,800 KB
testcase_16 AC 952 ms
44,672 KB
testcase_17 AC 1,177 ms
44,800 KB
testcase_18 AC 1,188 ms
44,928 KB
testcase_19 AC 1,184 ms
44,928 KB
testcase_20 AC 858 ms
51,712 KB
testcase_21 AC 890 ms
51,456 KB
testcase_22 AC 870 ms
51,456 KB
testcase_23 AC 882 ms
51,456 KB
testcase_24 AC 898 ms
51,456 KB
testcase_25 AC 903 ms
51,456 KB
testcase_26 AC 902 ms
51,712 KB
testcase_27 AC 895 ms
51,456 KB
testcase_28 AC 881 ms
51,456 KB
testcase_29 AC 887 ms
51,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
from collections import deque
for _ in range(m):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
d=[-1]*(n+1)
d[1]=0
q=deque()
q.append(1)
while q:
    now=q.popleft()
    for to in g[now]:
        if d[to]==-1:
            d[to]=d[now]+1
            q.append(to)
print(d[n])
0