sort(heap) + BFS, good job leetcode admin
Hi LeetCode Admin, congratulation, you made every python code using sort(heap) + BFS TLE again. Good job on wasting people\'s time. I thought I did something wr
Hi LeetCode Admin, congratulation, you made every python code using sort(heap) + BFS TLE **again**. Good job on wasting people\'s time. I thought I did something wrong, but checked some code from discuss, same TLE. \n\n```\nclass Solution:\n    def cutOffTree(self, forest: List[List[int]]) -> int:\n        m, n = len(forest), len(forest[0])\n        if forest[0][0] == 0:\n            return -1\n        # Have priority queue that stores (height,x,y) for each tree in order of min to max.\n        # Use BFS to find the next available smallest height in priority queue.\n        heap = []\n    \n        for i in range(m):\n            for j in range(n):\n                if forest[i][j] > 1:\n                    heappush(heap, (forest[i][j], i, j))\n                    \n        \n        def bfs(sx, sy, tx, ty):\n            \n            visited = set()\n            visited.add((sx, sy))\n            \n            queue = deque()\n            queue.append((sx, sy))\n            d = 0\n            while queue:\n                for _ in range(len(queue)):\n                    cx, cy = queue.popleft()\n                    if cx == tx and cy == ty:\n                        forest[cx][cy] = 1\n                        return d\n\n                    for nx, ny in ((cx+1, cy), (cx-1, cy), (cx, cy-1), (cx, cy+1)):\n                        if 0 <= nx < m and 0 <= ny < n and forest[nx][ny] != 0 and(nx, ny) not in visited:\n                            queue.append((nx, ny))\n                            visited.add((nx, ny))\n\n                d += 1\n            return -1\n        \n        ans = 0\n        prev_x, prev_y = 0, 0\n        while heap:\n            _, x, y = heappop(heap)\n            \n            step = bfs(prev_x, prev_y, x, y)\n            if step == -1:\n                return -1\n            ans += step\n            prev_x, prev_y = x, y\n        return ans\n            \n```
[]