Python heap solution
Use visited, time, and cost to memorize the status of each node, update if necessary.\nUse a minheap to prioritize cost, time.\n\n\nclass Solution:\n    def min
Use visited, time, and cost to memorize the status of each node, update if necessary.\nUse a minheap to prioritize cost, time.\n\n```\nclass Solution:\n    def minCost(self, maxTime: int, edges: List[List[int]], passingFees: List[int]) -> int:\n        \n        n = len(passingFees)\n        g = collections.defaultdict(list)\n        for u, v, t in edges:\n            g[u].append((v, t))\n            g[v].append((u, t))\n        \n        times = [0] + [float(\'inf\')] * (n - 1)\n        costs = [passingFees[0]] + [float(\'inf\')] * (n - 1)\n        q = [(passingFees[0], 0, 0)] # cost, time, node\n        visited = set()\n        visited.add(0)\n        while q:\n            cost, time, node = heapq.heappop(q)\n            if node == n - 1:\n                if time <= maxTime:\n                    return cost\n                else:\n                    return -1\n            for neighbor, t in g[node]:\n                if time + t <= maxTime and (neighbor not in visited or cost + passingFees[neighbor] < costs[neighbor] or time + t < times[neighbor]):\n                    visited.add(neighbor)\n                    times[neighbor] = min(times[neighbor], time + t)\n                    costs[neighbor] = min(costs[neighbor], cost + passingFees[neighbor])\n                    heapq.heappush(q, (cost + passingFees[neighbor], time + t, neighbor))\n                    \n        return -1\n```
['Heap (Priority Queue)', 'Python']