C++ Dijkstra
See my latest update in repo LeetCode\n\n## Solution 1. Dijkstra\n\nUse a min-heap to have the nodes with the smallest cost at the top.\n\n\n\n\ncpp\n// OJ: htt
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Dijkstra\n\nUse a min-heap to have the nodes with the smallest cost at the top.\n\n![image](https://assets.leetcode.com/users/images/d70e3034-ecac-4912-82ef-b9bb5a40741a_1625943562.271901.png)\n\n\n```cpp\n// OJ: https://leetcode.com/problems/minimum-cost-to-reach-destination-in-time/\n// Author: github.com/lzl124631x\n// Time: O(ElogE)\n// Space: O(V + E)\nclass Solution {\n    typedef array<int, 3> Node; // node, time, cost\npublic:\n    int minCost(int maxTime, vector<vector<int>>& E, vector<int>& F) {\n        int N = F.size();\n        vector<unordered_map<int, int>> G(N);\n        vector<int> minTime(N, maxTime + 1);\n        for (auto &e : E) {\n            int u = e[0], v = e[1], t = e[2];\n            if (G[u].count(v)) { // For duplicated edges, we just need to keep track of the edge with smallest time.\n                G[u][v] = G[v][u] = min(G[u][v], t);\n            } else {\n                G[u][v] = G[v][u] = t;\n            }\n        }\n        auto cmp = [](auto &a, auto &b) { return a[2] > b[2]; }; // min-heap: Heap top is the node with the smallest cost to reach\n        priority_queue<Node, vector<Node>, decltype(cmp)> pq(cmp);\n        pq.push({0, 0, F[0]});\n        minTime[0] = 0;\n        while (pq.size()) {\n            auto [u, time, c] = pq.top();\n            pq.pop();\n            if (u == N - 1) return c;\n            for (auto &[v, t] : G[u]) {\n                int nt = time + t, nc = c + F[v];\n                if (nt < minTime[v]) {\n                    minTime[v] = nt;\n                    pq.push({v, nt, nc});\n                }\n            }\n        }\n        return -1;\n    }\n};\n```
[]