Optimised Dijkstra Algo C++
\nclass Solution {\npublic:\n    // dry run kia for whole day.... maja aa gya\n    vector<vector<int>> graph[1001];\n    int time[1001], cost[1001];\n    int di
```\nclass Solution {\npublic:\n    // dry run kia for whole day.... maja aa gya\n    vector<vector<int>> graph[1001];\n    int time[1001], cost[1001];\n    int dijikstra(int src, int dest, int maxTime) {\n        for (int i = 1; i <= dest; ++i) {\n            time[i] = INT_MAX;\n            cost[i] = INT_MAX;\n        }\n        priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;\n        pq.push({cost[src], time[src], src});\n        while (!pq.empty()) {\n            vector<int> temp = pq.top(); pq.pop();\n            int c = temp[0];\n            int t = temp[1];\n            int u = temp[2];\n            \n            for (int i = 0; i < graph[u].size(); ++i) {\n                if (t + graph[u][i][1] <= maxTime) {\n                    if (c + graph[u][i][2] < cost[graph[u][i][0]]) {\n                        cost[graph[u][i][0]] = c + graph[u][i][2];\n                        time[graph[u][i][0]] = t + graph[u][i][1];\n                        pq.push({cost[graph[u][i][0]], time[graph[u][i][0]], graph[u][i][0]});\n                    } else if (graph[u][i][1] + t < time[graph[u][i][0]]) {\n                        time[graph[u][i][0]] = graph[u][i][1] + t;\n                        pq.push({c + graph[u][i][2], time[graph[u][i][0]], graph[u][i][0]});\n                    }\n                }\n            }\n        }\n        return cost[dest];\n    }\n    int minCost(int maxTime, vector<vector<int>>& arr, vector<int>& fee) {\n        int n = arr.size();\n        // graph.assign(n, vector<int>());\n        // time.assign(n, INT_MAX);\n        // cost.assign(n, INT_MAX);\n        \n        for (int i = 0; i < n; ++i) {\n            int u = arr[i][0];\n            int v = arr[i][1];\n            int t = arr[i][2];\n            \n            graph[u].push_back({v, t, fee[v]});\n            graph[v].push_back({u, t, fee[u]});\n        }\n        \n        cost[0] = fee[0];\n        time[0] = 0;\n        \n        int ans = dijikstra(0, fee.size() - 1, maxTime);\n        if (ans == INT_MAX) return -1;\n        return ans;\n    }\n};\n```
['C']