Java Solution - Dijkstra Algorithm (Inbuilt min-heap trick)
Since the inbuilt implementation of priorty queue in java does not support updating the keys once they are inserted, we could insert duplicate nodes in the queu
Since the inbuilt implementation of priorty queue in java does not support updating the keys once they are inserted, we could insert duplicate nodes in the queue. Once we have visited a node, we can discard all of its duplicates whenever they appear.\n\n```\nclass Solution {\n    int ans = 0;\n    \n    public int networkDelayTime(int[][] times, int N, int K) {\n        ArrayList<int[]> adj[] = new ArrayList[N];      // (node, weight)\n        for(int i = 0; i < N; i++){\n            adj[i] = new ArrayList<>();\n        }\n        \n        for(int t[]: times){\n            adj[t[0] - 1].add(new int[]{t[1] - 1, t[2]});\n        }\n    \n        boolean visited[] = new boolean[N];\n        dijkstra(K-1, adj, visited);\n        \n        for(boolean v: visited){\n            if(!v){\n                return -1;\n            }\n        }\n        \n        return ans;\n    }\n    \n    public void dijkstra(int source, ArrayList<int[]> adj[], boolean visited[]){\n        PriorityQueue<int[]> pq = new PriorityQueue<>(new Comparator<>(){\n            public int compare(int a[], int b[]){\n                return a[1] - b[1];\n            } \n        });\n        \n        pq.add(new int[]{source, 0});\n        while(!pq.isEmpty()){   \n            int node[] = pq.poll();\n\n            // skip duplicate nodes\n            if(visited[node[0]]){\n                continue;\n            }\n            \n            visited[node[0]] = true;            \n            ans = node[1];\n            \n            for(int neighbor[]: adj[node[0]]){\n                pq.add(new int[]{neighbor[0], neighbor[1] + node[1]});\n            }\n        }\n    }\n}\n```
[]