#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define REPR(i, n) for(ll i = n;i >= 0;i--) #define FOR(i, m, n) for(ll i = m;i < n;i++) #define FORR(i, m, n) for(ll i = m;i >= n;i--) #define REPO(i, n) for(ll i = 1;i <= n;i++) #define ll long long #define INF (ll)1ll << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(),n.end() #define MOD (ll)1000000007 #define P pair ll d[210000]; struct edge { ll to, cost; }; vector g[210000]; void dijkstra(ll a) { priority_queue, greater

> q; fill(d, d + 210000, INF); d[a] = 0; q.push(P(0, a)); while (!q.empty()) { P p = q.top(); q.pop(); ll v = p.second; if (d[v] < p.first) continue; REP(i, g[v].size()) { edge e = g[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; q.push(P(d[e.to], e.to)); } } } } int main(){ ll n, m, x; cin >> n >> m >> x; REP(i, m){ ll a, b, c, d; cin >> a >> b >> c >> d; a--; b--; g[a].push_back({b, c + x * d}); g[b].push_back({a, c + x * d}); } dijkstra(0); cout << (d[n - 1] == INF ? -1 : (d[n - 1] + x - 1) / x) << endl; }