#include using namespace std; using ll = long long; constexpr ll mod = 998244353; template struct Mint { using M=Mint; ll v; M& put(ll x) { v=(x>=1; } return res; } M inv() { return pow(mod-2); } }; using mint = Mint; int main(){ cin.tie(0); cin.sync_with_stdio(0); int n, m, x; cin >> n >> m >> x; vector>> edges(n); for(int i = 0; i < m; ++i){ int u, v, c, t; cin >> u >> v >> c >> t; --u, --v; edges[u].emplace_back(v, c + t * x); edges[v].emplace_back(u, c + t * x); } vector dp(n, 1e18); dp[0] = 0; priority_queue, vector>, greater<>> que; que.emplace(0, 0); while(!que.empty()){ auto [d, pos] = que.top(); que.pop(); if(dp[pos] != d)continue; for(auto [to, cos] : edges[pos]){ if(dp[to] > d + cos){ dp[to] = d + cos; que.emplace(d + cos, to); } } } if(dp.back() == 1e18){ cout << -1 << endl; } else{ cout << (dp.back() + x - 1) / x << endl; } }