#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int n = 55 * 305; int m; vector> graph(n,vector()); vector Dijkstra(int start){ vector seen(55 * 305,false); vector shortest(55 * 305,LINF); priority_queue,greater> pq; pq.push(pll(0,start)); while(!pq.empty()){ ll dist = pq.top().first; int node = pq.top().second; pq.pop(); if(seen[node]) continue; shortest[node] = dist; seen[node] = true; for(pll next:graph[node]){ int next_node = next.second; ll next_cost = next.first; if(seen[next_node]) continue; pq.push(pll(next_cost + dist,next_node)); } } return shortest; } int main(){ cin >> n; int c; cin >> c; cin >> m; vector a(m),b(m),y(m),t(m); rep(i,m) cin >> a[i],--a[i]; rep(i,m) cin >> b[i],--b[i]; rep(i,m) cin >> y[i]; rep(i,m) cin >> t[i]; rep(i,m){ for(int j=y[i];j<=300;j++){ graph[a[i]*301+j].push_back(pll(t[i],b[i]*301+j-y[i])); //graph[b[i]*301+j].push_back(pll(t[i],a[i]*301+j-y[i])); } } vector answer = Dijkstra(0 + c); ll ans = LINF; rep(i,c+1){ ans = min(ans,answer[(n-1)*301+i]); } if(ans==LINF) cout << -1 << endl; else cout << ans << endl; return 0; }