Structured explanation - Minimum Cost Path in Time-Bound Travel 
IntuitionWe need to find the minimum cost to reach city n - 1 from city 0 within a given maxTime. Since traveling between cities takes different amounts of time
# Intuition
###### We need to find the minimum cost to reach city n - 1 from city 0 within a given maxTime. Since traveling between cities takes different amounts of time and costs vary, this problem can be solved using ***Dijkstra’s Algorithm***, where the goal is to find the minimum cost instead of the shortest path.
1. Each city has a passing fee, and we must consider this cost while traveling.
2. We can only visit cities if the total travel time does not exceed maxTime.
3. Unlike traditional Dijkstra’s Algorithm (which optimizes for shortest path), we must optimize for minimum cost.
4. Using a priority queue (min-heap) helps process cities in increasing order of cost.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
1. Graph Representation:
Use an adjacency list where graph[i] stores neighboring cities and their travel time.
We do not store passing fees in the adjacency list, as they are stored separately.
2. Priority Queue (Dijkstra’s Variant):
Each node in the queue is stored as a Pair (node, time, cost), where:
node → current city
time → total time spent so far
cost → total cost spent so far
The queue is sorted by cost (lowest first), ensuring we process cheaper paths first.
3. Dijkstra's Exploration:
Start from city 0 with time = 0 and cost = passingFees[0].
Use two tracking arrays:
minCost[i] → Minimum cost to reach city i.
minTime[i] → Minimum time required to reach city i.
While processing a node, iterate over its neighbors and update minCost and minTime accordingly.
If reaching a neighbor results in a cheaper cost or lesser time, update and push it into the priority queue.
4. Final Result:
After processing all possible paths, return minCost[n-1].
If city n-1 is unreachable within maxTime, return -1.
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: $$O(ElogE)$$ (where E is the number of edges).
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(n+E)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
import java.util.*;

class Solution {
    static class Pair implements Comparable<Pair> {
        int node, time, cost;
        public Pair(int node, int time, int cost) {
            this.node = node;
            this.time = time;
            this.cost = cost;
        }
        @Override
        public int compareTo(Pair p2) {
            return this.cost - p2.cost; // Prioritize lower cost first
        }
    }

    public int minCost(int maxTime, int[][] edges, int[] passingFees) {
        int n = passingFees.length;
        List<List<int[]>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) graph.add(new ArrayList<>());

        // Build the graph
        for (int[] edge : edges) {
            int u = edge[0], v = edge[1], time = edge[2];
            graph.get(u).add(new int[]{v, time});
            graph.get(v).add(new int[]{u, time});
        }

        // Distance & cost tracking
        int[] minCost = new int[n];
        int[] minTime = new int[n];
        Arrays.fill(minCost, Integer.MAX_VALUE);
        Arrays.fill(minTime, Integer.MAX_VALUE);
        minCost[0] = passingFees[0];
        minTime[0] = 0;

        // Priority Queue for Dijkstra (minHeap)
        PriorityQueue<Pair> pq = new PriorityQueue<>();
        pq.add(new Pair(0, 0, passingFees[0]));

        while (!pq.isEmpty()) {
            Pair curr = pq.poll();

            // If exceeding maxTime, skip
            if (curr.time > maxTime) continue;

            for (int[] next : graph.get(curr.node)) {
                int nextNode = next[0];
                int travelTime = next[1];
                int newTime = curr.time + travelTime;
                int newCost = curr.cost + passingFees[nextNode];

                // If within maxTime and better cost/time, update
                if (newTime <= maxTime) {
                    if (newCost < minCost[nextNode]) {
                        minCost[nextNode] = newCost;
                        minTime[nextNode] = newTime;
                        pq.add(new Pair(nextNode, newTime, newCost));
                    } else if (newTime < minTime[nextNode]) {
                        minTime[nextNode] = newTime;
                        pq.add(new Pair(nextNode, newTime, newCost));
                    }
                }
            }
        }

        return minCost[n - 1] == Integer.MAX_VALUE ? -1 : minCost[n - 1];
    }
}

```
['Graph', 'Shortest Path', 'Java']