Deal with search mode correctly for BFS and DFS.
Count number of expanded nodes.