Java | using MinHeap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int networkDelayTime(int[][] times, int n, int k) {\n     Map<Integer,List<int[]>> map=new HashMap<>();\n     for(int i[]:times)\n     {\n         if(!map.containsKey(i[0]))map.put(i[0],new ArrayList<>());\n         map.get(i[0]).add(new int[]{i[1],i[2]});\n     }\n    \n    Set<Integer> visited=new HashSet<>();\n    Queue<int[]> minheap=new PriorityQueue<>((a,b)->a[1]-b[1]);\n\n    minheap.add(new int[]{k,0});\n    int ans=0;\n     while(!minheap.isEmpty())\n     {\n         int val[]=minheap.poll();\n         int src=val[0],w=val[1];\n         if(visited.contains(src))continue;\n         visited.add(src);\n         ans=w;\n         if(!map.containsKey(src))continue;\n        for(int i[]:map.get(src))\n        {\n            minheap.add(new int[]{i[0],i[1]+w});\n        }\n     }\n     return visited.size()==n?ans:-1;\n\n    }\n}\n```
['Java']