Java Dijkstra With Clean and Commented Solution 100%
\nclass Solution {\n    \n    public int total = 0; // to return the max value\n    \n    public class Edge  // As graph is arrayList of edges so firstly creati
```\nclass Solution {\n    \n    public int total = 0; // to return the max value\n    \n    public class Edge  // As graph is arrayList of edges so firstly creating an edge class\n    {\n        int src;  // source\n        int nbr; // its destination or source\'s neighbour\n        int wt; // corresponding edge weight\n        \n        Edge(int src , int nbr , int wt)  // constructor to initialise the new Edge object\n        {\n            this.src = src;\n            this.nbr = nbr;\n            this.wt = wt;\n        }\n    }\n    \n    public int networkDelayTime(int[][] times, int n, int k) {\n        \n        List<Edge>[] graph = new ArrayList[n+1]; // Adjacency List for representation of graph {n+1} because edge starts from **1 to N**\n        \n        Set<Integer> set = new HashSet(); // if all nodes are visited then return result else return -1 as mentioned\n        \n        for(int i=1;i<=n;i++)\n        {\n            graph[i] = new ArrayList();  // Creating the Adjacency list like for Node 1 ----> [] , Node 2 -----> []\n        }\n        \n        \n        \n        for(int i=0;i<times.length;i++)\n        {\n            // Graph creation\n            int v1 = times[i][0];\n            int v2 = times[i][1];\n            int wt = times[i][2];\n            graph[v1].add(new Edge(v1, v2, wt));  // as it is directed graph obviously only one edge to be connected\n            \n        }\n        \n\t\t// At this point our graph is ready and ready to execute this problem\n\t\t\n\t\t// As the source is K is the question and from K we need to visit all the nodes\n\t\t\n        PriorityQueue<Pair> pq = new PriorityQueue<>(); // Min PriorityQueue for Dijkstras\n        \n         boolean[] vis = new boolean[n+1]; // {n+1} because 1toN nodes not 0 to N-1\n        \n        pq.add(new Pair(k,0)); //initialising the priorityQueue \n        \n        while(pq.size() > 0)\n        {\n            Pair rem = pq.remove();\n            \n            if(vis[rem.v])  // If the node is already visited then just continue\n            {\n                continue;\n            }\n            \n            vis[rem.v] = true; //else mark it as true\n            set.add(rem.v); // this is for final result comparing\n            total = Math.max(total , rem.wsf); // max until now\n            \n            for(Edge e : graph[rem.v]) // visiting the neighbours using the current node \n            {\n                if(vis[e.nbr] == false)\n                {\n                      pq.add(new Pair(e.nbr  , rem.wsf+e.wt)); // prev wt + curr wt\n                      \n                }\n            }\n            \n        }\n        \n        if(set.size() == n)\n        {\n            return total;\n        }\n        return -1;\n        \n        \n    }\n    \n    public class Pair implements Comparable<Pair> // As pq is of type Pair we need to mention how it is been compared with hence we go on with comparable class\n    {\n        int v;\n        int wsf;\n        Pair(int v , int wsf)\n        {\n            this.v = v;\n            this.wsf = wsf;\n        }\n        \n        public int compareTo(Pair o) // Inbuilt method when used comparable interface and has to be compulsorily defined\n        {\n            return this.wsf - o.wsf;\n        }\n    }\n}\n\n//Please upvote if you found this informative\n```
['Heap (Priority Queue)', 'Java']