EASY BFS SOLUTION
Intuition\nFirst of all, we will determine the order in which we have to cut the trees. Let\'s say that we have to cut the trees in the order [t3, t2, t4, t1]. 
# Intuition\nFirst of all, we will determine the order in which we have to cut the trees. Let\'s say that we have to cut the trees in the order [t3, t2, t4, t1]. We will start by going to t3 from (0,0), then proceed to cut t3. Afterward, we will move to t2 from t3, then to t4, and finally to t1.\n\n# Approach\nCreated a vector of tuples to sort in the desired way, then performed BFS to each target position from the current position.\n\n# Complexity\n- Time complexity:\n\n- Space complexity:\n\n# Code\n```\n#define mypair pair<int, pair<int, int>>\nclass Solution {\npublic:\n    int cutOffTree(vector<vector<int>>& forest) {\n        int n = forest.size(), m = forest[0].size();\n        vector<mypair> trees;\n        for(int i=0; i<n; i++)\n            for(int j=0; j<m; j++)\n                if(forest[i][j] > 1) \n                    trees.push_back({forest[i][j], {i, j}});\n        sort(trees.begin(), trees.end());\n        /* \n        created the order to cut the tree, \n        so will find the distance to traver each of them one by one.\n        */\n\n        int steps = 0;\n        int sx=0, sy=0;\n        for(int i=0; i<trees.size(); i++){\n            int ex = trees[i].second.first;\n            int ey = trees[i].second.second;\n            int req = minSteps(forest, sx, sy, ex, ey);\n            if(req < 0) return -1;\n            steps += req;\n            sx = ex; \n            sy = ey;\n        }\n        return steps;\n    }\n\n    // find the minimum steps to move from {sx, sy} to {ex, ey}\n    int minSteps(vector<vector<int>>& forest, int sx, int sy, int ex, int ey){\n        if(sx==ex && sy==ey)return 0;\n        int n = forest.size(), m = forest[0].size();\n        vector<vector<bool>> vis(n, vector<bool>(m, false));\n\n        vector<int> dx = {-1, 0, 1, 0};\n        vector<int> dy = {0, 1, 0, -1};\n\n        queue<pair<int, pair<int, int>>> q;\n        q.push({0, {sx, sy}});\n        vis[sx][sy]=true;\n        while(!q.empty()){\n            mypair node = q.front();\n            q.pop();\n            sx = node.second.first; sy = node.second.second;\n            for(int j=0; j<4; j++){\n                int nx = sx + dx[j];\n                int ny = sy + dy[j];\n                if(checkValid(forest, nx, ny) ){\n                    if(!vis[nx][ny]){\n                        vis[nx][ny] = true;\n                        if(nx==ex && ny==ey){\n                            forest[nx][ny]=1;\n                            return node.first+1;\n                        }\n                        q.push({node.first+1, {nx, ny}});\n                    }\n                }\n            }\n        }\n        return -1;\n    }\n\n    bool checkValid(vector<vector<int>>& forest, int x, int y){\n        int n = forest.size(), m = forest[0].size();\n        if(x>=0 && x<n && y>=0 && y<m && forest[x][y] >= 1) return true;\n        return false;\n    }\n};\n```
['C++']