Swift💯
Modified Dijkstra (accepted answer)\nWe cannot "idle" on a node waiting for access to a neighbor, instead we must hop back and forth with a previous node. This 
**Modified Dijkstra (accepted answer)**\nWe cannot "idle" on a node waiting for access to a neighbor, instead we must hop back and forth with a previous node. This is calculated, not simulated, so to do that, we must factor in the parity of the difference of time `t` arriving at node `P` and `t+Q.minT` of node `Q`. This is calculated as `((Q.minT - t) & 1 + 1)&1`, or more simply, `((Q.minT-t)&1^1)`\n```\nimport Algorithms\nimport Collections\nclass Solution {\n    struct HeapItem: Comparable {\n        var t,x,y:Int\n        var tuple: (Int,Int,Int) {(t,x,y)}\n        public static func <(a:Self, b:Self)->Bool {a.t<b.t}\n    }\n\n    func minimumTime(_ grid: [[Int]]) -> Int {\n        guard min(grid[1][0], grid[0][1]) < 2 else { return -1 }\n        let deltas = [0,1,0,-1,0].adjacentPairs()\n        let (rows, cols) = (grid.count, grid[0].count)\n        var visited = Array(repeating: Array(repeating: false, count: cols), count: rows)\n        var heap = Heap([HeapItem(t:grid[0][0],x:0,y:0)])\n        \n        while let (time, c, r) = heap.popMin()?.tuple {\n            guard !visited[r][c] else { continue }\n            guard (r,c) != (rows-1, cols-1) else { return time }\n            for (x,y) in deltas.lazy.map{dx,dy in (c+dx, r+dy)}\n              where 0..<cols ~= x && 0..<rows ~= y && !visited[y][x] {\n                let t = max(grid[y][x] + ((grid[y][x]-time)&1^1), time+1)\n                heap.insert(HeapItem(t:t,x:x,y:y))\n            }\n            visited[r][c] = true\n        }\n        return -1\n    }\n}\n```
['Swift']