without BFS