Breath First Search, modifying the code to include edgeto