import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner(System.in); int N = cin.nextInt(); int C = cin.nextInt(); int V = cin.nextInt(); ArrayList> graph = new ArrayList>(); for(int i = 0; i < N ; i++)graph.add(new ArrayList()); int S[] = new int[V],T[] = new int[V] , Y[] = new int[V], M[] = new int[V]; int arr[][] = {S,T,Y,M}; for(int[] v:arr) for(int i = 0 ; i < V ; i++) v[i] = cin.nextInt(); for(int i = 0 ; i < V ; i++ ){ graph.get(S[i]-1).add(new Edge(T[i]-1,M[i],Y[i])); } System.out.println(Dijkstra(graph,0,N-1,C)); } public static class Edge implements Comparable{ int weight ; int dst; int money; Edge(int dst , int weight,int money){ this.weight = weight; this.dst = dst; this.money = money; } @Override public int compareTo(Object obj){ try{ Edge e = (Edge)obj ; if(this.weight > e.weight)return 1 ; else if(this.weight < e.weight)return -1; else return 0; }catch(ClassCastException e){ //ignore } return 0 ; } } static int Dijkstra(ArrayList> graph, int src,int dst,int C){ PriorityQueue qu = new PriorityQueue(); int N = graph.size(); qu.add(new Edge(src,0,0)); int visited[][] = new int[N][C+1]; for(int[] v : visited)Arrays.fill(v, 1<<29); while(!qu.isEmpty()){ Edge e = qu.poll(); if(e.dst == dst) return (int)e.weight; if(e.weight > visited[e.dst][e.money])continue; visited[e.dst][e.money] = e.weight; List nxt = graph.get(e.dst); for(Edge next :nxt){ if(next.money + e.money > C)continue; if(visited[next.dst][next.money+e.money] > next.weight + e.weight ){ qu.add(new Edge(next.dst,next.weight+e.weight,next.money+e.money)); } } } return -1; } }