#include using namespace std; using ll=long long; namespace Lib { struct DSU { vector par, sz; DSU(int n) : par(n), sz(n) { fill(par.begin(), par.end(), -1); fill(sz.begin(), sz.end(), 1); } int leader(int a) { if (par[a] == -1) return a; return par[a] = leader(par[a]); } void merge(int a, int b) { a = leader(a), b = leader(b); if (a == b) return; if (sz[a] > sz[b]) swap(a, b); par[a] = b; sz[b] += sz[a]; } bool same(int a, int b) { a = leader(a), b = leader(b); return a == b; } int size(int v) { v = leader(v); return sz[v]; } }; } // namespace Lib int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,K; ll C; cin>>N>>K>>C; vector E(K,array()); for(int i=0;i>E[i][1]>>E[i][2]>>E[i][0]>>E[i][3]; --E[i][1],--E[i][2]; } sort(E.begin(),E.end()); vector tree(N,vector(0,array())); Lib::DSU dsu(N); int base=0; for(int i=0;ibfs; vector dist(N,(int)1e9); bfs.push(0); dist[0]=0; while(bfs.size()){ int v=bfs.front(); bfs.pop(); for(auto [i,w]:tree[v]){ if(dist[i]>dist[v]+1){ dist[i]=dist[v]+1; bfs.push(i); lca[i][0]=v; w_max[i][0]=w; } } } for(int j=0;jbt){ swap(a,b); swap(at,bt); } for(int i=0;i>i&1){ ret=max(ret,w_max[b][i]); b=lca[b][i]; } } if(a==b){ return ret; } for(int i=bit_N-1;i>=0;i--){ int ra=lca[a][i],rb=lca[b][i]; if(ra!=-1&&ra!=rb){ ret=max({ret,w_max[a][i],w_max[b][i]}); a=ra,b=rb; } } ret=max({ret,w_max[a][1],w_max[b][1]}); return ret; }; int ans=base; for(int i=0;i