[java] | min_heap | dijkstra | easy | priority queue
Please comment incase of any questions\n\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        Map<Integer,Map<Int
Please comment incase of any questions\n```\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        Map<Integer,Map<Integer,Integer>> adjGrp = new HashMap<>();\n        adjGrp = getAdjGrp(edges);\n        int n = passingFees.length;\n        if(noValidPath(adjGrp,n))\n            return -1;\n        int[] timeTaken = new int[n];\n        Arrays.fill(timeTaken,Integer.MAX_VALUE);\n        PriorityQueue<int[]> minHeap = new PriorityQueue<>((a,b) -> a[1]-b[1]); \n        timeTaken[0] = 0;  //0 is the staring point\n        minHeap.offer(new int[]{0,passingFees[0],0});\n        int dest = n-1;\n        while(!minHeap.isEmpty()){\n            int[] nodeSrc = minHeap.poll();\n            int currTime = nodeSrc[2];\n            int currCost = nodeSrc[1];\n            int u = nodeSrc[0];\n            if(u == dest){\n                return currCost;\n            }\n            for(Map.Entry<Integer,Integer> vertex : adjGrp.get(u).entrySet()){\n                int v = vertex.getKey();\n                int time = vertex.getValue();\n                int fee = passingFees[v]; \n                if(currTime+time > maxTime)\n                    continue; \n                if(currTime+time < timeTaken[v]){\n                    timeTaken[v] = currTime+time;\n                    minHeap.offer(new int[]{v,fee+currCost,timeTaken[v]});                \n                }                \n            }                        \n        }\n        return -1;        \n        \n        \n    }\n    public boolean noValidPath(Map<Integer,Map<Integer,Integer>> adjGrp , int n ){\n        for(int i = 0 ; i < n ;i++){\n            if(!adjGrp.containsKey(i))\n                return true;\n        }\n        return false;\n    }\n    \n    //Optimization by taking on fastest road if 2 available \n    public Map<Integer,Map<Integer,Integer>> getAdjGrp(int[][] edges){\n        Map<Integer,Map<Integer,Integer>> adjGrp = new HashMap<>();\n        for(int i=0;i<edges.length;i++){\n            int u = edges[i][0];\n            int v = edges[i][1];\n            int t = edges[i][2];\n            adjGrp.putIfAbsent(u,new HashMap<Integer,Integer>());\n            adjGrp.putIfAbsent(v,new HashMap<Integer,Integer>());   \n            if(!adjGrp.get(u).containsKey(v))\n                adjGrp.get(u).put(v,t);                \n            else{\n                if(adjGrp.get(u).get(v) > t) {\n                    adjGrp.get(u).put(v,t); \n                }\n            }\n            if(!adjGrp.get(v).containsKey(u))\n                adjGrp.get(v).put(u,t);                \n            else{\n                if(adjGrp.get(v).get(u) > t )\n                    adjGrp.get(v).put(u,t);\n            }\n            \n        }\n        return adjGrp; \n    }\n}\n```
[]