C# 62ms Runtime Dijkstra with array instead of priority queue
Approach\n\nUsing List<(int, int)>[200_000] in place of PriorityQueue<(int, int, int), int> sped up the Dijkstra implementation x5.\n\nThe constant 200_000 must
# Approach\n\nUsing `List<(int, int)>[200_000]` in place of `PriorityQueue<(int, int, int), int>` sped up the Dijkstra implementation `x5`.\n\nThe constant `200_000` must be greater than `m * n + Max(grid[i][j])`\n\n\n![image.png](https://assets.leetcode.com/users/images/dbb87e58-c791-45e8-a4c5-90b51c3672e3_1732842621.541828.png)\n\n\n# Code\n```csharp []\npublic class Solution {\n    private int[] directions = [0, 1, 0, -1, 0];\n    public int MinimumTime(int[][] grid) {\n        if (grid[1][0] > 1 && grid[0][1] > 1)\n        {\n            return -1;\n        }\n        int m = grid.Length;\n        int n = grid[0].Length;\n        bool[,] visited = new bool[m, n];\n        visited[0, 0] = true;\n        List<(int, int)>[] queue = new List<(int, int)>[200_000];\n        queue[0] = [(0, 0)];\n        for (int time = 0; time < 200_000; time++)\n        {\n            if (queue[time] is null)\n            {\n                continue;\n            }\n            while (queue[time].Count > 0)\n            {\n                (int x, int y) = queue[time][^1];\n                queue[time].RemoveAt(queue[time].Count-1);\n                for (int i = 0; i < 4; i++)\n                {\n                    int a = x + directions[i];\n                    int b = y + directions[i+1];\n                    if (a < 0 || a >= m || b < 0 || b >= n || visited[a, b])\n                    {\n                        continue;\n                    }\n                    int newTime = Math.Max(\n                        time + 1,\n                        grid[a][b] + (grid[a][b] + a + b) % 2\n                    );\n                    if (a == m-1 && b == n-1)\n                    {\n                        return newTime;\n                    }\n                    visited[a, b] = true;\n                    if (queue[newTime] is null)\n                    {\n                        queue[newTime] = [(a, b)];\n                    }\n                    else\n                    {\n                        queue[newTime].Add((a, b));\n                    }\n                }\n            }\n        }\n        throw new Exception();\n    }\n}\n```
['C#']