#include using namespace std; using pl=pair; using Graph=vector>; vector dijkstra(long long v,long long n,Graph &g){ vector d(n,8e18); priority_queue,greater> pq; d[v]=0; pq.push({0,v}); while(!pq.empty()){ pl od=pq.top();pq.pop(); if(d[od.second]!=od.first){continue;} for(auto &nx : g[od.second]){ if(d[nx.first]>od.first+nx.second){ d[nx.first]=od.first+nx.second; pq.push({d[nx.first],nx.first}); } } } return d; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); long long n,m,x; cin >> n >> m >> x; x--; Graph g(n); for(long long i=0;i> u >> v >> c >> t; u--;v--; g[u].push_back({v,t*x+c}); g[v].push_back({u,t*x+c}); } vector d=dijkstra(0,n,g); // for(auto &nx : d){cout << nx << " ";}cout << "\n"; if(d[n-1]>4e18){cout << "-1\n";} else{ cout << (d[n-1]+x-1)/x << "\n"; } return 0; }