$ ./guess_the_languageProblem Solving — fill the blank
Problem Solving — fill the blank · medium · #325

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 (also accepted: 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 ▸