#include #define rep(i, n) for(int i=0, i##_len=(n); i=0; --i) #define rreps(i, n) for(int i=((int)(n)); i>0; --i) #define all(v) (v).begin(), (v).end() using namespace std; using ll = long long; using ull = unsigned long long; using vi = vector; using vvi = vector>; using vvvi = vector>>; using vl = vector; using vvl = vector>; using vvvl = vector>>; using vs = vector; using pi = pair; using pl = pair; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (bbool chmaxeq(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; } templatebool chmineq(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; } bool yes(bool a) { cout << (a?"yes":"no") << endl; return a; } bool Yes(bool a) { cout << (a?"Yes":"No") << endl; return a; } bool YES(bool a) { cout << (a?"YES":"NO") << endl; return a; } void _main(); int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); _main(); return 0; } long long INF = 1LL << 60; using P = pair; struct Edge { long long to, cost; Edge(long long to, long long cost) : to(to), cost(cost) {} }; struct Graph { vector> g; vector d; vector prev; Graph(long long n) { g.resize(n); d.assign(n, INF); prev.assign(n, -1); } void add_edge(long long from, long long to, long long cost) { g[from].push_back(Edge(to, cost)); } void add_indirected_edge(long long from, long long to, long long cost) { add_edge(from, to, cost); add_edge(to, from, cost); } void dijkstra(long long s) { d[s] = 0; priority_queue, greater

> q; q.push({0, s}); while (!q.empty()) { P p = q.top(); q.pop(); long long v = p.second; if (d[v] < p.first) continue; for (auto &e : g[v]) { if (d[e.to] > d[v]+e.cost) { d[e.to] = d[v]+e.cost; prev[e.to] = v; q.push({d[e.to], e.to}); } } } } vector get_path(long long t) { vector path; for (long long cur = t; cur != -1; cur = prev[cur]) { path.push_back(cur); } reverse(path.begin(), path.end()); return path; } }; void _main() { ll N, M, X; cin >> N >> M >> X; Graph g(N); rep(i, M) { ll u, v, C, T; cin >> u >> v >> C >> T; u--; v--; g.add_indirected_edge(u, v, C+T*X); } g.dijkstra(0); cout << (g.d[N-1]==INF?-1:(g.d[N-1]+X-1)/X) << endl; }