#include using namespace std; using ll = long long; const ll INF = 1e18; int main(){ ll n, m, x; cin >> n >> m >> x; vector>> graph(n); for (int i = 0; i < m; i++) { ll u, v, c, t; cin >> u >> v >> c >> t; u--, v--; graph[u].emplace_back(v, t * x + c); graph[v].emplace_back(u, t * x + c); } priority_queue, vector>, greater>> q; vector cst(n, INF); q.push({0, 0}); cst[0] = 0; while (!q.empty()) { auto [c, p] = q.top(); q.pop(); if (cst[p] != c) continue; for(auto [to, cp] : graph[p]){ if(cst[p] + cp < cst[to]){ cst[to] = cst[p] + cp; q.push({cst[to], to}); } } } if(cst[n - 1] == INF){ cout << -1 << endl; }else{ cout << (cst[n-1] + x - 1) / x << endl; } }