How can I use BFS to solve the multiple finding problem in POJ 1426?