結果

問題 No.1565 Union
ユーザー convexineqconvexineq
提出日時 2021-07-09 07:36:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 305 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 113,412 KB
最終ジャッジ日時 2024-04-28 02:05:10
合計ジャッジ時間 7,411 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,712 KB
testcase_01 AC 35 ms
51,840 KB
testcase_02 AC 40 ms
51,840 KB
testcase_03 AC 35 ms
51,968 KB
testcase_04 AC 34 ms
52,096 KB
testcase_05 AC 34 ms
52,096 KB
testcase_06 AC 38 ms
52,224 KB
testcase_07 AC 37 ms
52,480 KB
testcase_08 AC 35 ms
51,840 KB
testcase_09 AC 36 ms
52,224 KB
testcase_10 AC 151 ms
80,768 KB
testcase_11 AC 227 ms
94,080 KB
testcase_12 AC 217 ms
85,504 KB
testcase_13 AC 115 ms
80,384 KB
testcase_14 AC 237 ms
92,160 KB
testcase_15 AC 339 ms
109,168 KB
testcase_16 AC 275 ms
98,488 KB
testcase_17 AC 343 ms
109,104 KB
testcase_18 AC 348 ms
108,852 KB
testcase_19 AC 357 ms
109,404 KB
testcase_20 AC 205 ms
113,084 KB
testcase_21 AC 210 ms
113,352 KB
testcase_22 AC 207 ms
113,196 KB
testcase_23 AC 218 ms
112,888 KB
testcase_24 AC 206 ms
113,240 KB
testcase_25 AC 222 ms
113,012 KB
testcase_26 AC 216 ms
113,072 KB
testcase_27 AC 221 ms
113,028 KB
testcase_28 AC 221 ms
113,412 KB
testcase_29 AC 217 ms
113,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

d = [-1]*n
d[0] = 0
q = [0]
for v in q:
    for c in g[v]:
        if d[c] == -1:
            d[c] = d[v] + 1
            q.append(c)
print(d[-1])
0