shortestPath, BFS and print functions