Simple Java Solution using BFS (similar to dijkstra's shortest path algorithm) with explanation
The idea is to find the time to reach every other node from given node K\nThen, to check if all nodes can be reached and if it can be reached then return the ti
The idea is to find the time to reach every other node from given node K\nThen, to check if all nodes can be reached and if it can be reached then return the time taken to reach the farthest node (node which take longest to get the signal).\nAs the signal traverses concurrently to all nodes, we have to find the maximum time it takes to reach a node among all nodes from given node K.\nIf any single node takes Integer.MAX_Value, then return -1, as not all nodes can be reached\n\nadd the index of all the nodes which can be reached from a node to a list and store this list in a hashmap\n\nthen its similar to dijkstra's shortest path algorithm except that I am not using Priority Queue to get the minimum distance node. See comments.\n```\nclass Solution {\n    public int networkDelayTime(int[][] times, int N, int K) {\n        int r = times.length, max = Integer.MAX_VALUE;\n        \n        Map<Integer,List<Integer>> map = new HashMap<>();\n        for(int i=0;i<r;i++){\n            int[] nums = times[i];\n            int u = nums[0];\n            int v = nums[1];\n            List<Integer> list = map.getOrDefault(u,new ArrayList<>());\n            \n            list.add(i);\n            \n            map.put(u,list);\n        }\n        if(map.get(K) == null){\n            return -1;// no immediate neighbor of node K, so return -1\n        }\n        int[] dist = new int[N+1];//dist[i] is the time taken to reach node i from node k\n        Arrays.fill(dist,max);\n        \n        dist[K] = 0;\n        Queue<Integer> queue = new LinkedList<>();\n        \n        queue.add(K);\n        \n        while(!queue.isEmpty()){\n            int u = queue.poll();\n            int t = dist[u];\n            List<Integer> list = map.get(u);// get the indices of all the neighbors of node u\n            if(list == null)\n                continue;\n            \n            for(int n:list){\n                int v = times[n][1];\n                int time = times[n][2];// time taken to reach from u to v\n                 if(dist[v] > t + time){// if time taken to reach v from k is greater than time taken to reach from k to u + time taken to reach from u to v, then update dist[v]\n                    dist[v] = t + time;\n                    queue.add(v);// as we have found shorter distance to node v, explore all neighbors of v\n                }                \n            }\n        }\n        \n        int res = -1;\n        \n        for(int i=1;i<=N;i++){\n            int d = dist[i];\n            if(d == max){// if d is max, it means node i can not be reached from K, so return -1\n                return -1;\n            }\n            res = d > res ? d : res;\n        }\n        \n        return res;\n    }\n}\n```\n\nNote: I have updated the solution description and solution. Yes, my solution is not exactly dijkstra, but it was inspired by it and I thought it was very similar except that it is not very similar.
[]