package main import ( "fmt" ) type next struct { town, cost, time int } type costTime struct { cost, time int } func scanIntSet(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { fmt.Scan(&ret[i]) } return ret } func main() { // init var N, C, V int fmt.Scan(&N, &C, &V) S := scanIntSet(V) T := scanIntSet(V) Y := scanIntSet(V) M := scanIntSet(V) e := make(map[int][]next) for i := 0; i < V; i++ { e[S[i]] = append(e[S[i]], next{T[i], Y[i], M[i]}) } path := make([][]costTime, N+1) path[1] = append(path[1], costTime{0, 0}) for i := 1; i <= N; i++ { for _, now := range path[i] { nexts := e[i] for _, next := range nexts { if next.cost+now.cost > C { continue } path[next.town] = append(path[next.town], costTime{next.cost + now.cost, next.time + now.time}) } } } if path[N] == nil { fmt.Println(-1) return } min := 1000*V + 1 for _, p := range path[N] { if min > p.time { min = p.time } } fmt.Println(min) }