#include using namespace std; const int INF = 1e9; struct Edge { int to, cost, time; Edge(int t, int c, int ti) : to(t), cost(c), time(ti) {} }; int main() { int N, M, X; cin >> N >> M >> X; vector> graph(N); for (int i = 0; i < M; i++) { int u, v, c, t; cin >> u >> v >> c >> t; u--, v--; graph[u].emplace_back(v, c, t); graph[v].emplace_back(u, c, t); } vector dist(N, INF), money(N, 0); priority_queue, vector>, greater>> pq; dist[0] = 0; pq.emplace(0, 0); while (!pq.empty()) { int cost = pq.top().first; int curr = pq.top().second; pq.pop(); if (cost > dist[curr]) continue; for (Edge& e : graph[curr]) { int next_cost = cost + e.cost + e.time * X; int next_money = money[curr] + e.cost; if (next_cost < dist[e.to]) { dist[e.to] = next_cost; money[e.to] = next_money; pq.emplace(next_cost, e.to); } else if (next_cost == dist[e.to] && next_money < money[e.to]) { money[e.to] = next_money; pq.emplace(next_cost, e.to); } } } if (dist[N - 1] == INF) { cout << "-1" << endl; } else { cout << (dist[N - 1] + X - 1) / X << endl; } return 0; }