Graph traversal using a priority queue (Golang)
Intuition\nGraph traversal using a priority queue.\n\nIf the time difference with the neighboring cell is even, then we can go back and forth (for example, to t
# Intuition\nGraph traversal using a priority queue.\n\nIf the time difference with the neighboring cell is even, then we can go back and forth (for example, to the previous cell), thus "wait"\n\n# Code\n```\ntype Cell struct {\n\ttime int\n\trow  int\n\tcol  int\n}\n\ntype PriorityQueue []*Cell\n\nfunc (pq PriorityQueue) Len() int { return len(pq) }\n\nfunc (pq PriorityQueue) Less(i, j int) bool {\n\treturn pq[i].time < pq[j].time\n}\n\nfunc (pq PriorityQueue) Swap(i, j int) {\n\tpq[i], pq[j] = pq[j], pq[i]\n}\n\nfunc (pq *PriorityQueue) Push(x interface{}) {\n\t*pq = append(*pq, x.(*Cell))\n}\n\nfunc (pq *PriorityQueue) Pop() interface{} {\n\told := *pq\n\tn := len(old)\n\titem := old[n-1]\n\told[n-1] = nil\n\t*pq = old[0 : n-1]\n\treturn item\n}\n\nfunc minimumTime(grid [][]int) int {\n\tif grid[0][1] > 1 && grid[1][0] > 1 {\n\t\treturn -1\n\t}\n\n\tvar row, col, extra int\n\n\tm, n := len(grid), len(grid[0])\n\n\tvisited := make([]int, 1001*1001+1, 1001*1001+1)\n\n\tds := [][]int{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}\n\n\tpq := make(PriorityQueue, 0)\n\theap.Push(&pq, &Cell{grid[0][0], 0, 0})\n\n\tfor len(pq) > 0 {\n\t\tcell := heap.Pop(&pq).(*Cell)\n\n\t\tif cell.row == m-1 && cell.col == n-1 {\n\t\t\treturn cell.time\n\t\t}\n\n\t\tif visited[cell.row*1001+cell.col] == 1 {\n\t\t\tcontinue\n\t\t}\n\t\tvisited[cell.row*1001+cell.col] = 1\n\n\t\tfor _, d := range ds {\n\t\t\trow, col = cell.row+d[0], cell.col+d[1]\n\t\t\tif 0 <= row && row < m && 0 <= col && col < n && visited[row*1001+col] == 0 {\n\t\t\t\textra = 0\n\t\t\t\tif (grid[row][col]-cell.time)%2 == 0 {\n\t\t\t\t\textra = 1\n\t\t\t\t}\n\n\t\t\t\theap.Push(&pq, &Cell{max(cell.time+1, grid[row][col]+extra), row, col})\n\t\t\t}\n\t\t}\n\t}\n\n\treturn -1\n}\n\nfunc max(a, b int) int {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\n\n\n```
['Go']