What goes in the blank?
# BFS shortest path in an unweighted graph
for v in graph[u]:
if v not in dist:
dist[v] = dist[u] + ____
queue.append(v)
Answer: 1
Every edge costs one hop, and BFS reaches each node first along a shortest path, so its distance is its parent's plus 1.
Play Problem Solving ▸