#include using namespace std; using ll = long long; template using pq = priority_queue, greater>; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* 通った道の集合に対して ceil((sum Ci)/X) + sum Ti 時間かかる ceil((sum (Ci +Ti*X)) / X) 時間かかる */ ll N, M, X, u, v, C, T; cin >> N >> M >> X; ll from, alt, d; vector>> E(N); for (int i=0; i> u >> v >> C >> T; u--; v--; E[u].push_back({v, C+T*X}); E[v].push_back({u, C+T*X}); } pq> que; vector dist(N, 1e18); vector vst(N); dist[0] = 0; que.push({0, 0}); while(!que.empty()){ tie(d, from) = que.top(); que.pop(); if (vst[from]) continue; vst[from] = 1; for (auto [to, C] : E[from]){ alt = d + C; if (alt < dist[to]){ dist[to] = alt; que.push({dist[to], to}); } } } cout << (dist[N-1] == 1e18 ? -1 : (dist[N-1]+X-1) / X) << endl; return 0; }