problem is solved with breadth search method