結果

問題 No.1565 Union
ユーザー ygd.ygd.
提出日時 2021-06-28 20:05:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 582 ms / 2,000 ms
コード長 502 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 101,848 KB
最終ジャッジ日時 2023-09-07 21:06:43
合計ジャッジ時間 11,504 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
71,320 KB
testcase_01 AC 103 ms
71,324 KB
testcase_02 AC 100 ms
71,412 KB
testcase_03 AC 101 ms
71,352 KB
testcase_04 AC 99 ms
71,680 KB
testcase_05 AC 100 ms
71,596 KB
testcase_06 AC 102 ms
71,592 KB
testcase_07 AC 103 ms
71,476 KB
testcase_08 AC 104 ms
71,616 KB
testcase_09 AC 107 ms
71,488 KB
testcase_10 AC 276 ms
83,420 KB
testcase_11 AC 368 ms
94,376 KB
testcase_12 AC 378 ms
87,904 KB
testcase_13 AC 215 ms
82,404 KB
testcase_14 AC 438 ms
92,564 KB
testcase_15 AC 567 ms
100,912 KB
testcase_16 AC 468 ms
100,632 KB
testcase_17 AC 579 ms
100,828 KB
testcase_18 AC 543 ms
100,572 KB
testcase_19 AC 582 ms
100,628 KB
testcase_20 AC 287 ms
101,728 KB
testcase_21 AC 292 ms
101,724 KB
testcase_22 AC 289 ms
101,800 KB
testcase_23 AC 289 ms
101,764 KB
testcase_24 AC 297 ms
101,592 KB
testcase_25 AC 321 ms
101,616 KB
testcase_26 AC 316 ms
101,848 KB
testcase_27 AC 313 ms
101,488 KB
testcase_28 AC 310 ms
101,740 KB
testcase_29 AC 311 ms
101,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def main():
    N,M = map(int,input().split())
    G = [[] for _ 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)

    Q = deque([])
    Q.append(0)
    d = [-1]*N
    d[0] = 0
    while Q:
        v = Q.popleft()
        for u in G[v]:
            if d[u] != -1: continue
            d[u] = d[v] + 1
            Q.append(u)
    print(d[N-1])

if __name__ == '__main__':
    main()
0