Java || Dijkstra - Clean Code || 35ms Faster than 100%
I messed up basic Dijkstra and couldn\'t solve this during the contest. The idea is same as Dijkstra, with the only difference here is that we need to maintain 
I messed up basic Dijkstra and couldn\'t solve this during the contest. The idea is same as Dijkstra, with the only difference here is that we need to maintain another array to track the amount of `time` taken to reach every vertex. Unlike basic Dijkstra, this helps us to also keep the intermediate solutions with larger cost but lesser time in the priority queue. At every node we encounter in our path, we check if we\'ve reached the node before. If we\'ve reached the node before with a higher fees or with a higher time, we update the fees/time accordingly and add the node to the priority-queue.\n\n```\nclass Solution {\n        \n    public int minCost(int maxTime, int[][] edges, int[] fees) {\n        List<List<int[]>> graph = new ArrayList();\n        for (int i=0;i<fees.length;i++) {\n            graph.add(new ArrayList());\n        }\n        for (int[] edge: edges) {\n            graph.get(edge[0]).add(new int[]{edge[1], edge[2]});\n            graph.get(edge[1]).add(new int[]{edge[0], edge[2]});\n        }\n        int[] fees2Reach = new int[fees.length];\n        int[] time2Reach = new int[fees.length];\n        Arrays.fill(time2Reach, Integer.MAX_VALUE);\n        Arrays.fill(fees2Reach, Integer.MAX_VALUE);\n        time2Reach[0] = 0;\n        fees2Reach[0] = fees[0];\n        // sort by fees since we need minimum cost\n        PriorityQueue<int[]> pq = new PriorityQueue<int[]>((a, b) -> {\n            return a[1] - b[1];\n        });\n        pq.offer(new int[]{0, fees[0], 0}); // time, fees, city\n        while (!pq.isEmpty()) {\n            int[] arr = pq.poll();\n            if (arr[2]==fees.length-1) return arr[1];   // reached last city\n            for (int[] vertTime: graph.get(arr[2])) {\n                int vertex = vertTime[0];\n                int time = vertTime[1];\n                if (arr[0] + time > maxTime) continue;\n                if (arr[0] + time < time2Reach[vertex]) {\n                    time2Reach[vertex] = arr[0] + time;\n                    fees2Reach[vertex] = arr[1] + fees[vertex];\n                    pq.offer(new int[]{arr[0] + time, arr[1] + fees[vertex], vertex});\n                } else if (arr[1] + fees[vertex] < fees2Reach[vertex]) {\n                    fees2Reach[vertex] = arr[1] + fees[vertex];\n                    pq.offer(new int[]{arr[0] + time, arr[1] + fees[vertex], vertex});\n                }\n            }\n        }\n        return -1;\n    }\n}\n```
[]