結果
問題 | No.1565 Union |
ユーザー |
|
提出日時 | 2021-06-26 13:10:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 356 ms / 2,000 ms |
コード長 | 407 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 82,376 KB |
実行使用メモリ | 99,988 KB |
最終ジャッジ日時 | 2024-06-11 16:38:47 |
合計ジャッジ時間 | 7,326 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
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 -= 1G[a].append(b)G[b].append(a)from collections import dequeQ = deque([0])dist = [-1] * ndist[0] = 0while Q:now = Q.popleft()for nex in G[now]:if dist[nex] == -1:dist[nex] = dist[now] + 1Q.append(nex)print(dist[-1])