1Mark nodes as visited when you enqueue them, not when you dequeue — prevents adding the same node to the queue multiple times.
2For level-by-level processing, snapshot the queue size at the start of each level: `for i in range(len(queue))`.
3Multi-source BFS: add all source nodes to the queue before starting — they all start at distance 0.
4For grid problems, use a directions array `[(0,1),(0,-1),(1,0),(-1,0)]` for neighbor generation.