/*______    ||      |    ||ACはこちらへ|    ||      |    || ̄ ̄ ̄ ̄ ̄ ̄ ∧_∧|| (`・ω・|| ( つ||0  uーu*/ #include using namespace std; //output and debug template using V = vector; template ostream& operator<<(ostream& os, const pair& p) { return os << "P(" << p.first << ", " << p.second << ")"; } template ostream& operator<<(ostream& os,const V& v) { os << "["; bool f = false; for (auto d : v) { if (f) os << ", "; f = true; os << d; } return os << "]"; } template ostream& operator<<(ostream& os,const set& s) { os << "{"; bool f = false; for (auto d : s) { if (f) os << ", "; f = true; os << d; } return os << "}"; } template ostream& operator<<(ostream& os, const multiset& s) { os << "{"; bool f = false; for (auto d : s) { if (f) os << ", "; f = true; os << d; } return os << "}"; } template ostream& operator<<(ostream& os, const map& s) { os << "{"; bool f = false; for (auto p : s) { if (f) os << ", "; f = true; os << p.first << ": " << p.second; } return os << "}"; } template void o(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } #ifdef LOCAL #define dbg(...) \ do { \ cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \ o(__VA_ARGS__); \ cerr << endl; \ } while (false); #else #define dbg(...) #endif // input template void in(T&... a){ (cin >> ... >> a); } template void in(vector& a){ for(auto&& i : a) in(i); } template void in(pair& p){ in(p.first); in(p.second); } template void in(T& a){ cin >> a; } #define rep1(n) for(ll i = 0; i < n; ++i) #define rep2(i, n) for(ll i = 0; i < n; ++i) #define rep3(i, j, n) for(ll i = j; i < n; ++i) #define overload3(a, b, c, e, ...) e #define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(i,n) for(ll i = n-1;i>=0;--i) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using ll = long long ; using ld = long double; using pa = pair; using t2 = tuple; using tu = tuple; using vi = vector; using vs = vector; using vp = vector; using vvi = vector; using vvp = vector; using vvvi = vector; using v4 = vector; using vt = vector; const ll INF = (1ll << 29); const ll inf = INF*INF; const int dx[4]={1,-1,0,0}; const int dy[4]={0,0,1,-1}; void Yes(bool i = true){ return o(i?"Yes":"No"); } //reversed priority_queue template class prique :public std::priority_queue, std::greater> {}; const ll mod = 998244353; //const ll mod = 1000000007; int main(){ ll n,m,x; cin >> n >> m >> x; vi dist(n,inf); vvp g(n); rep(i,m){ ll u,v,c,t; cin >> u >> v >> c >> t; --u; --v; c += x*t; g[u].push_back(pa(c,v)); g[v].push_back(pa(c,u)); } auto daik = [&](){ priority_queue,vector>,greater>> q; q.push({0,0}); while(!q.empty()){ ll v,vc; tie(vc,v) = q.top(); q.pop(); if(dist[v]<=vc) continue; dist[v] = vc; for(auto to:g[v]){ auto u = to.second; auto uc = to.first; if(dist[u]<=vc+uc) continue; q.push({vc+uc,u}); } } return; }; daik(); if(dist[n-1] == inf) cout << -1 << endl; else cout << (dist[n-1]+x-1)/x << endl; }