/* -*- coding: utf-8 -*- * * 3616.cc: No.3616 WK vs AT vs MT vs SP - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 30000; const int L = 8; const int MAX_GN = (MAX_N + 1) * L; const long long LINF = 1LL << 60; /* typedef */ using ll = long long; using pil = pair; using vpil = vector; using pli = pair; /* global variables */ int xs[MAX_N], ys[MAX_N], zs[MAX_N]; ll ss[MAX_N]; vpil nbrs[MAX_GN]; ll ds[MAX_GN]; /* subroutines */ /* main */ int main() { int n, r; ll c; scanf("%d%d%lld", &n, &r, &c); for (int i = 0; i < n; i++) scanf("%d", xs + i); for (int i = 0; i < n; i++) scanf("%d", ys + i); for (int i = 0; i < n; i++) scanf("%d", zs + i); for (int i = 0; i < n; i++) scanf("%lld", ss + i); for (int i = 0; i < r; i++) { int up, vp, w, a, m; scanf("%d%d%d%d%d", &up, &vp, &w, &a, &m); up--, vp--; a = min(w, a); m = min(a, m); ll lws[] = {w, a, m, m, w, a, m, m}; for (int l = 0; l < L; l++) { int u = up * L + l, v = vp * L + l; nbrs[u].push_back({v, lws[l]}); nbrs[v].push_back({u, lws[l]}); } } for (int l = 4; l < L; l++) for (int up = 0; up < n; up++) { int u = up * L + l, v = n * L + l; nbrs[u].push_back({v, ss[up] + c}); nbrs[v].push_back({u, ss[up]}); } int gn = (n + 1) * L; fill(ds, ds + gn, LINF); ds[0] = 0; priority_queue q; q.push({0, 0}); ll gd = -1; while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; int up = u / L, ul = u % L; if (up == n - 1) { gd = ud; break; } if (! (u & 1)) { int v = (u | 1); ll vd = ud + xs[up]; if (ds[v] > vd) ds[v] = vd, q.push({-vd, v}); } if (! (u & 2)) { int v = (u | 2); ll vd = ud + ys[up]; if (ds[v] > vd) ds[v] = vd, q.push({-vd, v}); } if (! (u & 4)) { int v = (u | 4); ll vd = ud + zs[up]; if (ds[v] > vd) ds[v] = vd, q.push({-vd, v}); } for (auto [v, w]: nbrs[u]) { ll vd = ud + w; if (ds[v] > vd) ds[v] = vd, q.push({-vd, v}); } } printf("%lld\n", gd); return 0; }