an improved algorithm BFS DFS AdjacencyList