c++(128ms 93%) Dijkstra
Runtime: 128 ms, faster than 92.75% of C++ online submissions for Minimum Cost to Reach Destination in Time.\nMemory Usage: 25.1 MB, less than 94.35% of C++ onl
Runtime: 128 ms, faster than 92.75% of C++ online submissions for Minimum Cost to Reach Destination in Time.\nMemory Usage: 25.1 MB, less than 94.35% of C++ online submissions for Minimum Cost to Reach Destination in Time.\n```\nclass Solution {\npublic:\n  int minCost(int maxTime, vector<vector<int>>& edges, vector<int>& passingFees) {\n    int n = passingFees.size(), CITY = n - 1;\n    vector<vector<pair<int,int> > > graph(n);                        //city, time\n    vector<int> limtime(n, INT_MAX);\n    \n      \n    for(auto &i: edges ){\n      graph[i[0]].push_back({ i[1], i[2] });\n      graph[i[1]].push_back({ i[0], i[2] });\n    }\n     \n    priority_queue< tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>> > pq;  //pay, time, city\n    pq.push({0,0,0});\n    \n    while(!pq.empty()){\n      auto[pay, time, city] = pq.top(); pq.pop();                                                             \n      if(city == CITY) return pay + passingFees[0]; \n        \n      limtime[city] = time;\n        \n      for(auto &next: graph[city]){\n        int nexttime = time + next.second;\n        if( nexttime < limtime[next.first] ){\n          limtime[next.first] = nexttime;\n          if(nexttime <= maxTime) pq.push({ pay + passingFees[next.first], nexttime, next.first });\n        }\n      }\n    }\n    \n     return -1;      \n  }\n};\n```
['C', 'C++']