bfs dfs python implementation