#include #include #include #include #include using namespace std; int city_max,money_max,root_max; int from[1500],to[1500],moneyd[1500],timed[1500]; int func(int now, int money, int time){ int min_time = 999999999; int result; //現在地がゴールなら、所要時間を返す if(now == city_max){ return time; } //そうでなければ道を探す for(int i=0; i= 0){ result = func(to[i], money - moneyd[i], time + timed[i]); if(result != -1 && result < min_time){ min_time = result; } } } } //結果を返す if(result == 999999999){ return -1; }else{ return min_time; } } int main(){ int ans; cin >> city_max >> money_max >> root_max; for(int i=0; i> from[i]; } for(int i=0; i> to[i]; } for(int i=0; i> moneyd[i]; } for(int i=0; i> timed[i]; } cout << func(1, money_max, 0) << endl; return 0; }