#include #include int N, C, V; int M_min = 0; struct route { int S; int T; int Y; int M; }; struct route *Route; struct town { int route_n; int *route; }; struct town *Town; void go(int no, int Y, int M) { if (no == N) { M_min = M; } else { int i; struct town *townp = &(Town[no - 1]); for (i=0; iroute_n; i++) { struct route *routep = &(Route[townp->route[i]]); int YY = Y + routep->Y; int MM = M + routep->M; if (YY <= C && MM < M_min) { go(routep->T, YY, MM); } } } return; } int main() { int i; scanf("%d", &N); scanf("%d", &C); scanf("%d", &V); Route = (struct route*)malloc(sizeof(struct route)*V); for (i=0; iroute = (int*)malloc(sizeof(int)*V); townp->route_n = 0; townp++; } for (i=0; iroute[townp->route_n] = i; townp->route_n++; } go(1, 0, 0); if (check == M_min) { printf("%d\n", -1); } else { printf("%d\n", M_min); } return 0; }