function compare3DArray(a, b){ if(a[0] != b[0]){ if(a[0] < b[0]) return true; return false; } if(a[1] != b[1]){ if(a[1] < b[1]) return true; return false; } if(a[2] != b[2]){ if(a[2] < b[2]) return true; return false; } return false; } //https://www.geeksforgeeks.org/min-heap-in-javascript/ class MinHeap { constructor() { this.heap = []; } // Helper Methods getLeftChildIndex(parentIndex) { return 2 * parentIndex + 1; } getRightChildIndex(parentIndex) { return 2 * parentIndex + 2; } getParentIndex(childIndex) { return Math.floor((childIndex - 1) / 2); } hasLeftChild(index) { return this.getLeftChildIndex(index) < this.heap.length; } hasRightChild(index) { return this.getRightChildIndex(index) < this.heap.length; } hasParent(index) { return this.getParentIndex(index) >= 0; } leftChild(index) { return this.heap[this.getLeftChildIndex(index)]; } rightChild(index) { return this.heap[this.getRightChildIndex(index)]; } parent(index) { return this.heap[this.getParentIndex(index)]; } // Functions to create Min Heap swap(indexOne, indexTwo) { const temp = this.heap[indexOne]; this.heap[indexOne] = this.heap[indexTwo]; this.heap[indexTwo] = temp; } peek() { if (this.heap.length === 0) { return null; } return this.heap[0]; } // Removing an element will remove the // top element with highest priority then // heapifyDown will be called remove() { if (this.heap.length === 0) { return null; } const item = this.heap[0]; this.heap[0] = this.heap[this.heap.length - 1]; this.heap.pop(); this.heapifyDown(); return item; } add(item) { this.heap.push(item); this.heapifyUp(); } heapifyUp() { let index = this.heap.length - 1; while (this.hasParent(index) && this.parent(index) > this.heap[index]) { this.swap(this.getParentIndex(index), index); index = this.getParentIndex(index); } } heapifyDown() { let index = 0; while (this.hasLeftChild(index)) { let smallerChildIndex = this.getLeftChildIndex(index); if (this.hasRightChild(index) && this.rightChild(index) < this.leftChild(index)) { smallerChildIndex = this.getRightChildIndex(index); } if (compare3DArray(this.heap[index] , this.heap[smallerChildIndex])) { break; } else { this.swap(index, smallerChildIndex); } index = smallerChildIndex; } } printHeap() { var heap =` ${this.heap[0]} ` for(var i = 1; i= n || ny < 0 || ny >= m) continue; var nd = d + p[x][y]; if(nd < dist[nx][ny]){ dist[nx][ny] = nd; pq.add([nd, nx, ny]); } } } printf("%d\n", Math.floor(t / dist[x2][y2]));