1928. Minimum Cost to Reach Destination in Time.cpp
Code\n\nclass Solution {\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        unordered_map<int, vector<pair<
**Code**\n```\nclass Solution {\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        unordered_map<int, vector<pair<int, int>>> graph; \n        for (auto& edge : edges) {\n            graph[edge[0]].emplace_back(edge[1], edge[2]); \n            graph[edge[1]].emplace_back(edge[0], edge[2]); \n        }\n        priority_queue<array<int, 3>, vector<array<int, 3>>, greater<>> pq; // min-heap \n        pq.push({passingFees[0], 0, 0}); \n        unordered_map<int, int> dist = {{0, passingFees[0]}}; \n        while (pq.size()) {\n            auto [cost, k, t] = pq.top(); pq.pop(); \n            if (k == passingFees.size()-1) return cost; \n            for (auto& [kk, tt] : graph[k]) {\n                if (t + tt <= maxTime && (!dist.count(kk) || t + tt < dist[kk])) {\n                    dist[kk] = t + tt; \n                    pq.push({cost + passingFees[kk], kk, t + tt}); \n                }\n            }\n        }\n        return -1; \n    }\n};\n```
['C']