first version of direction optimal bfs. Starts with top-down, when frontier_size > unvisited_node_num, switch to bottom-up.