C++ program for three problems using templatized BFS algorithm