#!/usr/bin/env python3 import functools import itertools import operator def memoize(fn): table = {} def func(*args): if args not in table: table[args] = fn(*args) return table[args] return func N = int(input()) C = int(input()) V = int(input()) S = [int(s) for s in input().split()] T = [int(t) for t in input().split()] Y = [int(y) for y in input().split()] M = [int(m) for m in input().split()] RODE = list(zip(S, T, Y, M)) @memoize def path(town, yen): if town == 1: return [[1]] road = [path(s, yen - y) for s, t, y, m in RODE if t == town and yen >= y] if len(road) < 1: return [[-1]] return [p + [town] for p in functools.reduce(operator.add, road)] @memoize def roads(fr, to): return [(y, m) for s, t, y, m in RODE if s == fr and t == to] def cost_and_meter(roads): cost = 0 meter = 0 for road in roads: cost += road[0] meter += road[1] return (cost, meter) def min_cost_and_meter(path): road = [] for i in range(1, len(path)): road.append(roads(path[i - 1], path[i])) ways = itertools.product(*road) c_m = [cost_and_meter(way) for way in ways] path = [m for y, m in c_m if y <= C] if len(path) == 0: return -1 return min(path) meters = [m for m in [min_cost_and_meter(p) for p in path(N, C)] if m > 0] if len(meters) == 0: print(-1) else: print(min(meters))