bfs poj exercises