Simple Java, Dijkstra, heap, COMMENTS,
I could not find many solutions with comments so I decieded to write one up. I hope this helps someone. I am using Dijkstra\'s Algorithm.\n\n\nclass Solution {\
I could not find many solutions with comments so I decieded to write one up. I hope this helps someone. I am using Dijkstra\'s Algorithm.\n\n```\nclass Solution {\n    public int networkDelayTime(int[][] times, int n, int k) {\n        // init\n        Map<Integer, List<int[]>> graph = new HashMap<>();\n        \n        // create graph\n        // i usually use List<List<Integer>> graph..., but this graph is not zero based :(\n        for (int[] time : times) {\n            if(graph.get(time[0]) == null){\n                graph.put(time[0], new ArrayList<>());\n            }\n            graph.get(time[0]).add(new int[]{time[1], time[2]});\n        }\n        \n        // min heap to process cheapest edges first\n        PriorityQueue<int[]> queue = new PriorityQueue<>((a,b)->a[1] - b[1]);\n        \n        // start with edge k!\n        // k = starting edge\n        // 0 = the initial weight\n        queue.offer(new int[]{k, 0});\n        \n        // a map to keep track of distance for each node\n        Map<Integer, Integer> dist = new HashMap<>();\n        \n        // lets get started!\n        while(!queue.isEmpty()){\n            int[] curr = queue.poll();\n            \n            int node = curr[0];\n            int weight = curr[1];\n            \n            // since we are using a min heap we only need to iterate over each node once\n            if(dist.containsKey(node)){\n                continue;\n            }\n            dist.put(node, weight);\n            \n            // queue up the neighbors\n            if(graph.containsKey(node)){\n                for(int[] edge : graph.get(node)){\n                    // add the weight between this edge and the current node we are visiting\n                    // the weight to get from the src to this egde is n-1 + n\n                    queue.offer(new int[]{edge[0], edge[1] + weight});\n                }\n            }\n            \n        }\n        // we are missing a node :(\n        if(dist.size() != n){\n            return -1;\n        }\n        \n        // essentially, the max delay time is going to be the longest path\n        int result = Integer.MIN_VALUE;\n        \n        // iterate over each node and find the max distance (total weight) \n        for(int node : dist.keySet()){\n            result = Math.max(result, dist.get(node));\n        }\n        return result;\n    }\n}\n```
['Heap (Priority Queue)', 'Java']