[Java] Dijkstra's Algo with Heap
Runtime: 17ms (beat 62%)\nMemory Usage: 42MB(beat 83.23%)\n\n\nclass Solution {\n    public int networkDelayTime(int[][] times, int n, int k) {\n        Map<Int
Runtime: 17ms (beat 62%)\nMemory Usage: 42MB(beat 83.23%)\n\n```\nclass Solution {\n    public int networkDelayTime(int[][] times, int n, int k) {\n        Map<Integer, List<Cell>> graph = new HashMap<>();\n        for (int[] edge: times) {\n            graph.computeIfAbsent(edge[0], v->new ArrayList<>()).add(new Cell(edge[1],edge[2]));\n        }\n        \n        Map<Integer, Integer> costs = new HashMap<>();\n        PriorityQueue<Cell> heap = new PriorityQueue<>();\n        heap.add(new Cell(k, 0));\n        \n        while(!heap.isEmpty()) {\n            Cell curr = heap.poll();\n            if(costs.containsKey(curr.node)) continue;\n            costs.put(curr.node, curr.time);\n            \n            if (graph.containsKey(curr.node))  {\n                for(Cell neig: graph.get(curr.node)) {\n                    if (!costs.containsKey(neig.node)) {\n                        heap.add(new Cell(neig.node, neig.time+curr.time));\n                    }\n                }\n            }\n        }\n        int ans = -1;\n        if (costs.size() != n) return ans;\n        for (int cost: costs.values()) {\n            ans  = Math.max(ans, cost);\n        }\n        return ans;     \n    }\n}\n\nclass Cell implements Comparable<Cell> {\n    int node, time;\n    Cell(int node, int time) {\n        this.node = node;\n        this.time = time;\n    }    \n    public int compareTo(Cell c2) {\n        return  time-c2.time;\n    }\n}\n```
['Java']