bfs works with duplicate edge detection