#include #include #include #include using namespace std; struct Edge { int to, cost, time; }; struct State { int node, cost, time; bool operator>(const State& other) const { return time > other.time; } }; int shortestPath(int N, int C, vector>& graph) { vector> dp(N + 1, vector(C + 1, numeric_limits::max())); priority_queue, greater> pq; dp[1][0] = 0; pq.push({1, 0, 0}); while (!pq.empty()) { State curr = pq.top(); pq.pop(); if (curr.node == N) return curr.time; // Found shortest path to town N if (curr.time > dp[curr.node][curr.cost]) continue; for (Edge& e : graph[curr.node]) { int newCost = curr.cost + e.cost; int newTime = curr.time + e.time; if (newCost <= C && newTime < dp[e.to][newCost]) { dp[e.to][newCost] = newTime; pq.push({e.to, newCost, newTime}); } } } return -1; // No valid path within budget } int main() { int N, M, C; cin >> N >> M >> C; vector> graph(N + 1); for (int i = 0; i < M; i++) { int a, b, y, t; cin >> a >> b >> y >> t; graph[a].push_back({b, y, t}); graph[b].push_back({a, y, t}); // Assuming bidirectional roads } cout << shortestPath(N, C, graph) << endl; return 0; }