C++ Dijkastra + DP.
\nclass Solution {\n    typedef pair<int, int> edge;\n    struct cmp {\n        bool operator()(const array<int, 3> &first,\n                        const array
```\nclass Solution {\n    typedef pair<int, int> edge;\n    struct cmp {\n        bool operator()(const array<int, 3> &first,\n                        const array<int, 3> &second) {\n            return first[2] > second[2];\n        }\n    };\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n        unordered_map<int, vector<edge>> g;\n        for (auto v: edges) {\n            g[v[0]].push_back({v[1], v[2]});\n            g[v[1]].push_back({v[0], v[2]});\n        }\n        int n = passingFees.size();\n        std::priority_queue<array<int, 3>, vector<array<int, 3>>,\n                              cmp> q;\n        q.push({0, 0, passingFees[0]});\n        vector<int> nodeTimes(n, INT_MAX);\n        vector<vector<int>> dp(n, vector<int>(maxTime+1, INT_MAX));\n        while (q.empty() == false) {\n            auto [start, time, cost] = q.top();\n            if (start == n-1) break;\n            q.pop();\n            for (auto [node, ntime]: g[start]) {\n                if (time+ntime <= nodeTimes[node]) {\n                    if (time+ntime <= maxTime) {\n                        if (passingFees[node]+cost <= dp[node][time+ntime]) {\n                            nodeTimes[node] = time+ntime;\n                            dp[node][time+ntime] = passingFees[node]+cost;\n                            q.push({node, time+ntime, cost+passingFees[node]});\n                        }\n                    }\n                }\n            }\n        }\n        return (q.empty())?-1: *std::min_element(std::begin(dp[n-1]), std::end(dp[n-1]));    \n    }\n};\n```
[]