Javascript | Priority Queue
\nvar networkDelayTime = function (times, n, k) {\n    const edges = [];\n    for (let [u, v, w] of times) {\n        if (!edges[u]) edges[u] = [];\n        edg
```\nvar networkDelayTime = function (times, n, k) {\n    const edges = [];\n    for (let [u, v, w] of times) {\n        if (!edges[u]) edges[u] = [];\n        edges[u].push([v, w]);\n    }\n\n    function bfs() {\n        const pQueue = new MinPriorityQueue({ compare: (a, b) => a[1] > b[1] });\n        const visit = new Set();\n        pQueue.enqueue([k, 0]);\n        let maxPathTill = 0;\n\n        while (!pQueue.isEmpty()) {\n            const [node, w] = pQueue.dequeue();\n            if (visit.has(node)) continue;\n            visit.add(node);\n            maxPathTill = Math.max(maxPathTill, w);\n            if (edges[node]) {\n                const adjNodes = edges[node];\n                for (let [adjNode, adjW] of adjNodes) {\n                    if (!visit.has(adjNode)) pQueue.enqueue([adjNode, w + adjW])\n                }\n            }\n        }\n        return visit.size === n ? maxPathTill : -1;\n    }\n\n    return bfs()\n}\n```
['Queue', 'Heap (Priority Queue)', 'JavaScript']