use heap
neat DFS and BFS