fork download
  1. #define ll long long
  2. #define pb push_back
  3. int mod = 1e9+7;
  4. #define f first
  5. #define s second
  6.  
  7. class Solution {
  8.  
  9. vector<pair<int,int>>adj[100];
  10. int dp[100][100];
  11. int visited[100][100];
  12.  
  13.  
  14. int helper(int start , int node , int k , int dest){
  15.  
  16. if(start == dest){
  17.  
  18.  
  19. node--;
  20.  
  21. if(node <= k )
  22. return 0;
  23.  
  24. return INT_MAX;
  25.  
  26. }
  27.  
  28. int ans = INT_MAX;
  29.  
  30. if(node > k )
  31. return INT_MAX;
  32.  
  33.  
  34. if(dp[start][node] != -1)
  35. return dp[start][node];
  36.  
  37. if(visited[start][node] == 1)
  38. return INT_MAX;
  39.  
  40.  
  41. for(int i=0;i<adj[start].size();i++){
  42.  
  43.  
  44. int child = adj[start][i].f;
  45.  
  46. int val = helper(child , node+1 , k , dest);
  47.  
  48. if(val == INT_MAX)
  49. continue;
  50.  
  51. val+=adj[start][i].s;
  52.  
  53. ans = min(ans , val);
  54.  
  55. }
  56.  
  57. dp[start][node] = ans;
  58.  
  59. return ans;
  60. }
  61.  
  62. public:
  63. int findCheapestPrice(int n, vector<vector<int>>& flights, int src, int dst, int k) {
  64.  
  65. for(int i = 0 ; i < flights.size() ; i++){
  66.  
  67. adj[flights[i][0]].pb(pair<int,int>(flights[i][1],flights[i][2]));
  68. }
  69.  
  70.  
  71. for(int i = 0 ; i < n ; i ++){
  72.  
  73. for(int j = 0 ; j < 100 ; j++){
  74.  
  75. dp[i][j] = -1;
  76. visited[i][j] = -1;
  77. }
  78. }
  79.  
  80. int ans = helper(src , 0 , k , dst);
  81.  
  82. cout<<ans<<"\n";
  83.  
  84. if(ans==INT_MAX)
  85. return -1;
  86.  
  87. return ans;
  88.  
  89.  
  90. }};
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:9:1: error: ‘vector’ does not name a type
 vector<pair<int,int>>adj[100];
 ^~~~~~
prog.cpp:63:34: error: ‘vector’ has not been declared
     int findCheapestPrice(int n, vector<vector<int>>& flights, int src, int dst, int k) {
                                  ^~~~~~
prog.cpp:63:40: error: expected ‘,’ or ‘...’ before ‘<’ token
     int findCheapestPrice(int n, vector<vector<int>>& flights, int src, int dst, int k) {
                                        ^
prog.cpp: In member function ‘int Solution::helper(int, int, int, int)’:
prog.cpp:24:16: error: ‘INT_MAX’ was not declared in this scope
         return INT_MAX;
                ^~~~~~~
prog.cpp:24:16: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
 #define ll long long
prog.cpp:24:16:
         return INT_MAX;
                ^~~~~~~
prog.cpp:28:15: error: ‘INT_MAX’ was not declared in this scope
     int ans = INT_MAX;
               ^~~~~~~
prog.cpp:28:15: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:41:19: error: ‘adj’ was not declared in this scope
     for(int i=0;i<adj[start].size();i++){
                   ^~~
prog.cpp:53:15: error: ‘min’ was not declared in this scope
         ans = min(ans , val);
               ^~~
prog.cpp: In member function ‘int Solution::findCheapestPrice(int, int)’:
prog.cpp:65:25: error: ‘flights’ was not declared in this scope
     for(int i = 0 ; i < flights.size() ; i++){
                         ^~~~~~~
prog.cpp:67:9: error: ‘adj’ was not declared in this scope
         adj[flights[i][0]].pb(pair<int,int>(flights[i][1],flights[i][2]));
         ^~~
prog.cpp:67:31: error: ‘pair’ was not declared in this scope
         adj[flights[i][0]].pb(pair<int,int>(flights[i][1],flights[i][2]));
                               ^~~~
prog.cpp:67:36: error: expected primary-expression before ‘int’
         adj[flights[i][0]].pb(pair<int,int>(flights[i][1],flights[i][2]));
                                    ^~~
prog.cpp:67:40: error: expected primary-expression before ‘int’
         adj[flights[i][0]].pb(pair<int,int>(flights[i][1],flights[i][2]));
                                        ^~~
prog.cpp:80:23: error: ‘src’ was not declared in this scope
     int ans  = helper(src , 0 , k , dst);
                       ^~~
prog.cpp:80:33: error: ‘k’ was not declared in this scope
     int ans  = helper(src , 0 , k , dst);
                                 ^
prog.cpp:80:37: error: ‘dst’ was not declared in this scope
     int ans  = helper(src , 0 , k , dst);
                                     ^~~
prog.cpp:82:5: error: ‘cout’ was not declared in this scope
     cout<<ans<<"\n";
     ^~~~
prog.cpp:84:17: error: ‘INT_MAX’ was not declared in this scope
         if(ans==INT_MAX)
                 ^~~~~~~
prog.cpp:84:17: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
stdout
Standard output is empty