package leetcode;

/**
 * https://leetcode.com/problems/network-delay-time/
 */
public class Problem743 {
    public int networkDelayTime(int[][] times, int N, int K) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem743 prob = new Problem743();
        System.out.println(prob.networkDelayTime(new int[][]{
            {2, 1, 1}, {2, 3, 1}, {3, 4, 1}
        }, 4, 2)); // 2
    }
}

@@ -12,16 +12,148 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.PriorityQueue;%0A%0A
 /**%0A * h
@@ -306,259 +306,1396 @@
     
-// TODO%0A        return 0;%0A
+Map%3CInteger, List%3CEdge%3E%3E graph = new HashMap%3C%3E();%0A        for (int%5B%5D edge: times) %7B%0A   
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem743 prob = new Problem743();%0A        System.out.println(prob.networkDelayTime(new int%5B%5D%5B%5D%7B%0A            %7B2, 1, 1%7D, %7B2, 3, 1%7D, %7B3, 4, 1%7D%0A        %7D, 4, 2)); // 2
+ if (!graph.containsKey(edge%5B0%5D)) %7B%0A                graph.put(edge%5B0%5D, new ArrayList%3C%3E());%0A            %7D%0A            graph.get(edge%5B0%5D).add(new Edge(edge%5B1%5D, edge%5B2%5D));%0A        %7D%0A        PriorityQueue%3CEdge%3E pq = new PriorityQueue%3C%3E((a, b) -%3E Integer.compare(a.weight, b.weight));%0A        pq.add(new Edge(K, 0));%0A%0A        Map%3CInteger, Integer%3E dist = new HashMap%3C%3E();%0A%0A        while (!pq.isEmpty()) %7B%0A            Edge edge = pq.remove();%0A            if (dist.containsKey(edge.node)) %7B%0A                continue;%0A            %7D%0A            dist.put(edge.node, edge.weight);%0A            if (graph.containsKey(edge.node)) %7B%0A                for (Edge e : graph.get(edge.node)) %7B%0A                    if (!dist.containsKey(e.node)) %7B%0A                        pq.add(new Edge(e.node, edge.weight + e.weight));%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A%0A        if (dist.size() != N) %7B%0A            return -1;%0A        %7D%0A        int result = 0;%0A        for (int val : dist.values()) %7B%0A            result = Math.max(result, val);%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static class Edge %7B%0A        private final int node;%0A        private final int weight;%0A%0A        public Edge(int node, int weight) %7B%0A            this.node = node;%0A            this.weight = weight;%0A        %7D
 %0A   

Solve problem 743