Python heap
ApproachClassic Dijkstra but with some modifications.Whenever we pop a city off the heap, we know it's either the first time we visited the city or we have visi
# Approach
Classic Dijkstra but with some modifications.

Whenever we pop a city off the heap, we know it's either the first time we visited the city or we have visited the city at lower costs before. Hence, if we can reduce the time it took to that city, it's worth checking all its connected cities again.

# Complexity
- Time complexity:
O(N + ElogE) max heap length = edges length

- Space complexity:
O(N + E)

# Code
```python3 []
class Solution:
    def minCost(self, maxTime: int, edges: List[List[int]], passingFees: List[int]) -> int:
        import heapq
        import math
        N = len(passingFees)
        graph = [[] for _ in range(N)]
        for e in edges:
            graph[e[0]].append((e[1], e[2]))
            graph[e[1]].append((e[0], e[2]))
        minTime = [math.inf] * N
        # cost, city, time
        heap = [(passingFees[0], 0, 0)]

        while heap:
            cost, city, time = heapq.heappop(heap)
            if city == N - 1: return cost
            if minTime[city] <= time: continue
            minTime[city] = time

            for edge in graph[city]:
                nei = edge[0]
                new_time = time + edge[1]
                new_cost = cost + passingFees[nei]
                if new_time > maxTime: continue
                heapq.heappush(heap, (new_cost, nei, new_time))
        return -1
```
['Python3']