added code to do a bfs. It will only solve the first problem.