#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template ostream& operator<<(ostream& os, const set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const unordered_set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const atcoder::segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const atcoder::lazy_segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} using P = pair; int main(){ int N, M, C; cin >> N >> M >> C; vector> G(N, vector

(N, {-1, -1})); rep(_, M){ int u, v, r, w; cin >> u >> v >> r >> w; u--; v--; G[u][v] = {r, w}; G[v][u] = {r, w}; } int ans = -1; vector best(N, -1); for(int c = 1; c <= C; c++){ queue> qu; qu.emplace(0, c); while(qu.size()){ auto [from, c_from] = qu.front(); qu.pop(); if(c_from <= best[from]) continue; best[from] = c_from; if(from == N - 1) ans = c_from; for(int to = 0; to < N; to++){ auto [r, w] = G[from][to]; if(r == -1) continue; int c_to = c_from - (c_from / r + w); if(c_to < 0) continue; if(c_to <= best[to]) continue; qu.emplace(to, c_to); } } cout << ans << "\n"; } return 0; }