#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); ll n, m, x; cin >> n >> m >> x; vector Graph(n, vector>(0)); rep(_, m) { int u, v, c, t; cin >> u >> v >> c >> t; --u, --v; Graph[u].push_back({ v, c + t * x }); Graph[v].push_back({ u, c + t * x }); } priority_queue, vector>, greater<>> pq; constexpr ll INF = 1e18; vector dist(n, INF); pq.push({ 0, 0 }); dist[0] = 0; while (!pq.empty()) { auto [d, v] = pq.top(); pq.pop(); if (dist[v] < d) continue; for (auto [u, c] : Graph[v]) { if (dist[u] > dist[v] + c) { dist[u] = dist[v] + c; pq.push({ dist[u], u }); } } } if (dist[n - 1] == INF) { cout << -1 << '\n'; } else { cout << (dist[n - 1] + x - 1) / x << '\n'; } return 0; }