Java | 100% Faster Space & Time  | Dijkstra
\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        int[] time = new int[passingFees.length];\n        Arrays.f
```\nclass Solution {\n    public int minCost(int maxTime, int[][] edges, int[] passingFees) {\n        int[] time = new int[passingFees.length];\n        Arrays.fill(time, Integer.MAX_VALUE);\n        time[0] = 0;\n        \n        Map<Integer, List<List<Integer>>> edgesMap = new HashMap();\n        \n        for(int i = 0 ; i < edges.length ; i++){\n            if(!edgesMap.containsKey(edges[i][0]))\n                edgesMap.put(edges[i][0], new ArrayList());\n            if(!edgesMap.containsKey(edges[i][1]))\n                edgesMap.put(edges[i][1], new ArrayList());\n            \n            edgesMap.get(edges[i][0]).add(Arrays.asList(edges[i][1], edges[i][2]));\n            edgesMap.get(edges[i][1]).add(Arrays.asList(edges[i][0], edges[i][2]));\n        }\n        \n        Comparator<List<Integer>> cmp = (a,b) -> a.get(1) - b.get(1);\n        PriorityQueue<List<Integer>> pq = new PriorityQueue(cmp);\n        pq.add(Arrays.asList(0, passingFees[0], 0));\n        \n        while(!pq.isEmpty()){\n            List<Integer> node = pq.poll();\n            if(node.get(0) == passingFees.length - 1)\n                return node.get(1);\n            \n            List<List<Integer>> neighbours = edgesMap.get(node.get(0));\n            \n            for(int i = 0 ; i < neighbours.size() ; i++){\n                List<Integer> list = neighbours.get(i);\n                int timeToReach = node.get(2) + list.get(1);\n                \n                if(timeToReach > maxTime)\n                    continue;\n            \n                if(time[list.get(0)] > timeToReach){\n                    time[list.get(0)] = timeToReach;\n                    int cost = node.get(1) + passingFees[list.get(0)];\n                    pq.add(Arrays.asList(list.get(0),cost,timeToReach));\n                }\n            }\n        }\n        \n        return -1;\n    }\n}\n```
[]