remove unnecessary visited set from BFS (tree is acyclic)