Python BFS + MinHeap
\nclass Solution(object):\n    def cutOffTree(self, forest):\n        """\n        :type forest: List[List[int]]\n        :rtype: int\n        """\n        def 
```\nclass Solution(object):\n    def cutOffTree(self, forest):\n        """\n        :type forest: List[List[int]]\n        :rtype: int\n        """\n        def bfs(i, j, destx, desty):\n            q = deque()\n            visited = set()\n            q.append((i, j, 0))\n            while q:\n                x, y, step = q.popleft()\n                if x == destx and y == desty:\n                    return step\n                for dirx, diry in [(1, 0), (-1, 0), (0, 1), (0, -1)]:\n                    curx, cury = dirx + x, diry + y\n                    \n                    if 0 <= curx < m and 0 <= cury < n and forest[curx][cury] != 0 and (curx, cury) not in visited:\n                        q.append((curx, cury, step + 1))\n                        visited.add((curx, cury))\n            return -1\n                \n        \n        m, n = len(forest), len(forest[0])\n        \n        heap = []\n        for i in range(m):\n            for j in range(n):\n                if forest[i][j] > 1:\n                    heapq.heappush(heap, (forest[i][j], i, j))\n        \n        res = 0\n        i, j = 0, 0\n        while heap:\n            _, destx, desty = heapq.heappop(heap)\n            step = bfs(i, j, destx, desty)\n            # print i, j, destx, desty, step\n            if step < 0:\n                return -1\n            res += step\n            i, j = destx, desty\n        return res\n```
['Breadth-First Search', 'Heap (Priority Queue)', 'Python']