結果

問題 No.1565 Union
ユーザー roarisroaris
提出日時 2021-07-20 16:55:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 501 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 100,480 KB
最終ジャッジ日時 2024-04-28 09:11:05
合計ジャッジ時間 6,948 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,760 KB
testcase_01 AC 40 ms
53,632 KB
testcase_02 AC 40 ms
53,632 KB
testcase_03 AC 40 ms
53,632 KB
testcase_04 AC 40 ms
53,504 KB
testcase_05 AC 41 ms
53,760 KB
testcase_06 AC 40 ms
53,760 KB
testcase_07 AC 40 ms
53,504 KB
testcase_08 AC 40 ms
53,376 KB
testcase_09 AC 41 ms
53,504 KB
testcase_10 AC 112 ms
80,896 KB
testcase_11 AC 177 ms
92,416 KB
testcase_12 AC 158 ms
84,992 KB
testcase_13 AC 97 ms
80,000 KB
testcase_14 AC 196 ms
89,984 KB
testcase_15 AC 296 ms
98,688 KB
testcase_16 AC 234 ms
98,304 KB
testcase_17 AC 274 ms
99,072 KB
testcase_18 AC 286 ms
98,816 KB
testcase_19 AC 285 ms
99,072 KB
testcase_20 AC 147 ms
99,712 KB
testcase_21 AC 151 ms
99,968 KB
testcase_22 AC 163 ms
100,224 KB
testcase_23 AC 148 ms
99,840 KB
testcase_24 AC 150 ms
99,712 KB
testcase_25 AC 162 ms
100,096 KB
testcase_26 AC 161 ms
99,840 KB
testcase_27 AC 166 ms
99,840 KB
testcase_28 AC 167 ms
100,224 KB
testcase_29 AC 160 ms
100,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def bfs():
    q = deque([0])
    dist = [-1]*N
    dist[0] = 0
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist[-1]

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)

print(bfs())
0