Dijkstra's with slight modification
This concept can be generalised whenever minimization based on two things need to be done and when a parameter has to be just smaller than a threshold. \n1) In 
This concept can be generalised whenever minimization based on two things need to be done and when a parameter has to be just smaller than a threshold. \n1) In such  a case , we will make a min heap kind of thing with key or thing to minimize being the minimum value which we must return.\n2) The second parameter must be minimized for the cases if the first parameter minimization is  not done.\n\nThat is, priority wise minimization have to be considered.\n\nIn this question, we find that we have 2 reasons for putting an element in the multiset.\n1) If cost is decreased, and time required <= threshold time.\n2) Else if cost of the next won\'t be reduced, then we have to see if the time for next node is minimized, so that there is a possibility that some unexplored nodes are found.\n\nSo, performing these 2 cases, we wiil receive the most optimal cost to reach (n-1)th node following the threshold constraint.\n\nC++ code\n```\nclass Solution {\npublic:\n    int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& fees) {\n        \n        int n = fees.size();\n        \n        vector<pair<int,int>> vt[n];\n        \n        for(int i=0;i<edges.size();i++)\n        {\n            vt[edges[i][0]].push_back({edges[i][1],edges[i][2]});\n            \n            vt[edges[i][1]].push_back({edges[i][0],edges[i][2]});\n        }\n        \n        multiset<pair<int,pair<int,int>>> ms;\n        \n        ms.insert({fees[0],{0,0}});\n        \n        vector<int> tim(n,INT_MAX);\n        tim[0]= 0;\n        \n        vector<int> cost(n,INT_MAX);\n       \n        \n        while(!ms.empty())\n        {\n            pair<int,pair<int,int>> hr= *ms.begin();\n            \n            int cst= hr.first;\n            int cur= hr.second.first;\n            int tm= hr.second.second;\n            \n            ms.erase(ms.begin());\n            \n            \n            if(cur==n-1)\n                return cost[cur];\n            \n            for(auto it:vt[cur])\n            {\n                if(tm+it.second<=maxTime)\n                {\n                     if(cst+fees[it.first] < cost[it.first])\n                {\n                    cost[it.first]= cst+fees[it.first];\n                    tim[it.first]= tm+it.second;     \n                    ms.insert({cost[it.first],{it.first,tm+ it.second}});\n                }\n                    \n                else if( (tim[it.first] > tm + it.second)){\n                \n                    tim[it.first]= tm+it.second;\n                    ms.insert({cst+fees[it.first],{it.first,tm + it.second}});    \n                }\n            }\n            \n        }\n        }\n        return -1;\n        \n    }\n};\n```
[]