Rust
Code\nrust []\nuse std::collections::{HashSet, BinaryHeap};\nuse std::cmp::Reverse;\n\nimpl Solution {\n    pub fn minimum_time(grid: Vec<Vec<i32>>) -> i32 {\n 
# Code\n```rust []\nuse std::collections::{HashSet, BinaryHeap};\nuse std::cmp::Reverse;\n\nimpl Solution {\n    pub fn minimum_time(grid: Vec<Vec<i32>>) -> i32 {\n        if grid[0][1] > 1 && grid[1][0] > 1 {\n            return -1;\n        }\n\n        let (m, n) = (grid.len(), grid[0].len());\n        let mut q = BinaryHeap::from([Reverse((grid[0][0], 0, 0))]);\n        let mut visited = HashSet::from([(0, 0)]);\n        let mut res = -1;\n\n        while let Some(Reverse((time, x, y))) = q.pop() {\n            if x == m - 1 && y == n - 1 {\n                res = time;\n                break;\n            }\n\n            for (dx, dy) in [(0, 1), (1, 0), (0, -1), (-1, 0)] {\n                let (nx, ny) = ((x as i32 + dx) as usize, (y as i32 + dy) as usize);\n                if nx < m && ny < n && !visited.contains(&(nx, ny)) {\n                    visited.insert((nx, ny));\n                    let move_time = if (grid[nx][ny] - time) % 2 == 0 { 1 } else { 0 };\n                    q.push(Reverse(((time + 1).max(grid[nx][ny] + move_time), nx, ny)));\n                }\n            }\n        }\n\n        res\n    }\n}\n```
['Rust']