C#  A* Solution
Intuition\nCouldn\'t find a C# A implementation, so decided to make one myself\n\n# Approach\nPriority Queue to find target nodes\nThen A search for pathfinding
# Intuition\nCouldn\'t find a C# A* implementation, so decided to make one myself\n\n# Approach\nPriority Queue to find target nodes\nThen A* search for pathfinding.\n\n\n# Code\n```\npublic class Solution {\n    int ROWS;\n    int COLS;\n    IList<IList<int>> Forest;\n    public int CutOffTree(IList<IList<int>> forest)\n    {\n        ROWS = forest.Count;\n        COLS = forest[0].Count;\n        Forest = forest;\n        if (Forest[0][0] == 0)\n        {\n            return -1;\n        }\n        PriorityQueue<(int, int), int> pQue = new();\n        pQue.Enqueue((0, 0), 0);\n        for (int i = 0; i < ROWS; ++i)\n        {\n            for (int j = 0; j < COLS; ++j)\n            {\n                var current = forest[i][j];\n                if (current > 1)\n                {\n                    pQue.Enqueue((i, j), current);\n                }\n            }\n        }\n\n        if (pQue.Count < 2)\n        {\n            return 0;\n        }\n        var answer = 0;\n        var currentStep = pQue.Dequeue();\n\n        while (pQue.Count > 0)\n        {\n            var next = pQue.Dequeue();\n            var nextSteps = BFSPath(currentStep, next);\n            if (nextSteps == -1)\n            {\n                return -1;\n            }\n            answer += nextSteps;\n            currentStep = next;\n        }\n\n        return answer;\n    }\n\n    int BFSPath((int, int) start, (int, int) end)\n    {\n        Dictionary<int,int> costs = new();\n        PriorityQueue<MapNode,int> pQue = new();\n        (var endR, var endC) = end;\n        (var sr, var sc) = start;\n        var steps = -1;\n        var fNode = new MapNode(sr, sc, 0);\n        pQue.Enqueue(fNode, 0);\n        costs[fNode.r * COLS + fNode.c] = 0;\n        while (pQue.Count > 0)\n        {\n            var node = pQue.Dequeue();\n            if (node.r == endR && node.c == endC)\n            {\n                steps = node.depth;\n                break;\n            }\n            var nextNodes = new[] { (node.r + 1, node.c), (node.r - 1, node.c), (node.r, node.c + 1), (node.r, node.c - 1) };\n            foreach ((var r, var c) in nextNodes)\n            {\n                if (r >= 0 && r < ROWS && c >= 0 && c < COLS && Forest[r][c] != 0)\n                {\n                    var h = Heuristic(r, c, endR, endC);\n                    var cost = node.depth + 1 + h;\n                    if(costs.TryGetValue(r * COLS + c, out var pcost) && pcost <= cost){\n                        continue;\n                    }\n                    pQue.Enqueue(new MapNode(r, c, node.depth + 1), cost);\n                    costs[r * COLS + c] = cost;\n                }\n            }\n        }\n        return steps;\n    }\n    \n    int Heuristic(int r, int c, int er, int ec){\n        return Math.Abs(r - er) + Math.Abs(c - ec);\n    }\n\n    class MapNode\n    {\n        public int r;\n        public int c;\n        public int depth;\n\n        public MapNode(int R, int C, int Depth)\n        {\n            r = R;\n            c = C;\n            depth = Depth;\n        }\n\n        public override int GetHashCode()\n        {\n            return HashCode.Combine(r, c);\n        }\n    }\n}\n```
['C#']