Briefly Explained Approach
EXPLANATION:-\n    We can only visit the whole tree if we can go from lower to higher value cells.\n    Therefore we have to do something like we can go from cu
# EXPLANATION:-\n*    We can only visit the whole tree if we can go from lower to higher value cells.\n*    Therefore we have to do something like we can go from current cell to next greater cell.\n*    So we will do something like \n        1) Sort tree positions based on height of the tree \n        2) Aplly BFS to find shortest path between two points \n*  i.e we will first store all the cells in a 2D vector and sort them so that next cell to visit\n    will be next greater of current cell. \n* And then we will apply bfs in evry 2 pair of sorted new vector to see if we can reach to every current\'s next greater or not. \n* \tIf in any of the case we cant then return -1 from there only, otherwise keep going.\n* \tAnd if we are able to finish all pairs then return total number of steps calculated from every pair.\n*  Note:- All cell values stored in new array which was sorted after soring all cells values should be greater than 1 (should be a tree).\n\n* Example which may help:- [[1,2,3],[9,10,4],[7,6,5]]\n\n# CODE:-\n```\nclass Solution {\n    int Solve(vector<vector<int>> &forest, int src_row, int src_col, int dst_row, int dst_col){\n        int n = forest.size(), m = forest[0].size();\n        \n        if(src_row == dst_row && src_col == dst_col) {\n            return 0;\n        }\n        \n        queue<pair<int, int>> q;\n        q.push({src_row, src_col});\n        \n        vector<vector<int>> vis(n, vector<int>(m, 0));\n        vis[src_row][src_col] = 1;\n        \n        int step = 0;\n        while(!q.empty()){\n            int size = q.size();\n            while(size--){\n                int x = q.front().first, y = q.front().second;\n                q.pop();\n                \n                if(x == dst_row && y == dst_col){\n                    return step;\n                }\n            \n                int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};\n            \n                for(int k=0; k<4; k++){\n                    int newx = x+dx[k], newy = y+dy[k];\n                    if(newx>=0 && newy>=0 && newx<n && newy<m){\n                        if(vis[newx][newy] || !forest[newx][newy]) {\n                            continue;\n                        }\n                        vis[newx][newy] = 1;\n                        q.push({newx, newy});\n                    }\n                }\n            }\n            step+=1;\n        }\n        return -1;\n    }\npublic:\n    int cutOffTree(vector<vector<int>>& forest) {\n        int n = forest.size();\n        int m = forest[0].size();\n        \n        vector<vector<int>> trees;\n        \n        //storing all trees in a vector and sorting it\n        //storing in the format of {tree height, position} --> {forest[i], i, j}\n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                if(forest[i][j] > 1) \n\t\t\t\t\ttrees.push_back({forest[i][j], i, j});\n            }\n        }\n        \n        sort(trees.begin(), trees.end());\n        \n        int total_steps = 0;\n        int src_row = 0, src_col = 0;\n        for(int i=0; i<trees.size(); i++){\n            int dst_row = trees[i][1], dst_col = trees[i][2];\n            \n            //now bfs to find shorest distance from src to dst\n            int steps = Solve(forest, src_row, src_col, dst_row, dst_col);\n            \n            // if next tree cannot be reached\n            if(steps == -1) return -1;\n            \n            total_steps += steps;\n            \n            src_row = trees[i][1];\n            src_col = trees[i][2];\n        }\n        return total_steps;\n    }\n};\n```
[]