Question DSA-GRAPH-0041
MediumWhat is the output of this code?
from collections import deque
g = {0: [1, 2], 1: [3], 2: [3, 4], 3: [5], 4: [5], 5: []}
dist = {0: 0}
q = deque([0])
while q:
u = q.popleft()
for v in g[u]:
if v not in dist:
dist[v] = dist[u] + 1
q.append(v)
print(dist[5], len(dist))
- A.
3 6
- B.
2 6
- C.
Sign up free to see the answer and a step-by-step explanation.