#include using namespace std; using ll = long long; #define FOR(i, l, r) for(ll i = l; i < r; i++) #define rep(i, n) FOR(i, 0, n) #define FORR(i, l, r) for(ll i = r - 1; i >= l; i--) #define ALL(ar) begin(ar), end(ar) template inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const pair &p) { os << p.first << ' ' << p.second; return os; } template istream &operator>>(istream &is, vector &v) { for(T &x : v) is >> x; return is; } template ostream &operator<<(ostream &os, const vector &v) { for(size_t i = 0; i < v.size(); i++) os << (i ? " " : "") << v[i]; return os; } //------------------------------------------------- void solve() { ll N, M, X; cin >> N >> M >> X; vector>> g(N); rep(i, M) { ll u, v, c, t; cin >> u >> v >> c >> t; u--; v--; c += t * X; g[u].emplace_back(v, c); g[v].emplace_back(u, c); } vector dist(N, 1ll << 60); priority_queue, vector>, greater>> que; que.emplace(0, 0); dist[0] = 0; while(!que.empty()) { auto [d, v] = que.top(); que.pop(); if(dist[v] < d) continue; for(auto [to, cost] : g[v]) { if(chmin(dist[to], d + cost)) que.emplace(d + cost, to); } } if(dist[N - 1] == 1LL << 60) { cout << -1 << endl; } else { cout << (dist[N - 1] + X - 1) / X << endl; } } int main() { int t = 1; // cin >> t; while(t--) solve(); }