Pick your starting node. Call it . Create a queue and push into it. Mark as visited in your visited array. Set distance[s] to because the source is steps from itself.
Now you are ready to run the main BFS loop. The queue has one node, the visited array has one true entry, and the distance array has one finite value. Everything else is waiting to be discovered. This initialization ensures BFS starts correctly and maintains its invariants throughout execution.