#include #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif int main() { int n, k; ll c; cin >> n >> k >> c; vector u(k), v(k), w(k), p(k); rep(i,k) { cin >> u[i] >> v[i] >> w[i] >> p[i]; --u[i];--v[i]; } vector vs, ps; rep(i,k) vs.push_back(i); rep(i,k) ps.push_back(i); sort(vs.begin(),vs.end(),[&](int l, int r) { return w[l]c){ cout<<-1<1){ int mid = (high+low)/2; dsu uf(n); uf.merge(u[ps[mid]], v[ps[mid]]); ll sum = w[ps[mid]]; rep(i,k){ if(uf.same(u[vs[i]], v[vs[i]])) continue; uf.merge(u[vs[i]], v[vs[i]]); sum += w[vs[i]]; } if(sum<=c) low = mid; else high = mid; } cout << p[ps[low]] << endl; return 0; }