#include #include #include #include #include template struct WeightedGraph { constexpr static T INF = std::numeric_limits::max() >> 1; using edge_type = std::pair; private: std::vector> graph; public: explicit WeightedGraph(size_t size = 0) : graph(size) {} void add_edge(size_t from, size_t to, T cost) { graph.at(from).emplace_back(cost, to); } void add_undirected_edge(size_t u, size_t v, T cost) { add_edge(u, v, cost), add_edge(v, u, cost); } std::vector dijkstra(size_t start) const { std::vector min_costs(graph.size(), INF); std::vector done(graph.size()); std::priority_queue, std::greater<>> pq; pq.emplace(0, start); while (pq.size()) { auto [cost, v] = pq.top(); pq.pop(); if (done.at(v)) continue; min_costs.at(v) = cost, done.at(v) = true; for (const auto &[edge_cost, to] : graph.at(v)) { T new_cost = cost + edge_cost; if (new_cost < min_costs.at(to)) pq.emplace(new_cost, to); } } return min_costs; } }; int main() { using namespace std; using ull = unsigned long long; ull n, m, x; cin >> n >> m >> x; WeightedGraph g(n + 1); for (ull u, v, c, t, i = 0; i < m; ++i) cin >> u >> v >> c >> t, g.add_undirected_edge(u, v, c + t * x); auto cost = g.dijkstra(1).at(n); if (cost == WeightedGraph::INF) cout << "-1\n"; else cout << (cost + x - 1) / x << '\n'; return 0; }