amended BFS to print out the shortest distance?