#include using namespace std; class UnionFind{ public: vector par,siz; void make(int N){ par.resize(N,-1); siz.resize(N,1); } int root(int x){ if(par.at(x) == -1) return x; else return par.at(x) = root(par.at(x)); } void unite(int u, int v){ u = root(u),v = root(v); if(u == v) return; if(siz.at(u) < siz.at(v)) swap(u,v); par.at(v) = u; siz.at(u) += siz.at(v); } bool issame(int u, int v){ if(root(u) == root(v)) return true; else return false; } }; class LowestCommonAncestor{ public: vector> par,maxd; vector dist; void make(vector>> &Graph,int root){ int N = Graph.size(),K = 1; while((1<(N,-1)); maxd.resize(K,vector(N)); dist.resize(N,-1); dfs(Graph,root,-1,0); for(int i=1; i>> &Graph,int pos,int back,int d){ dist.at(pos) = d; par.at(0).at(pos) = back; for(auto [to,w] : Graph.at(pos)){ if(to == back) continue; maxd.at(0).at(to) = w; dfs(Graph,to,pos,d+1); } } int LCA(int u,int v){ int costu = 0,costv = 0; if(dist.at(u) < dist.at(v)) swap(u,v); int K = par.size(),diff = dist.at(u)-dist.at(v); for(int i=0; i=0; i--){ if(par.at(i).at(u) == par.at(i).at(v)) continue; u = par.at(i).at(u),v = par.at(i).at(v); costu = max(costu,maxd.at(i).at(u)),costv = max(costv,maxd.at(i).at(v)); } return max(costu,costv); } int twodist(int u,int v){ int lca = LCA(u,v); return dist.at(u)+dist.at(v)-2*dist.at(lca); } int twodist2(int u,int v){ } }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long N,K,C; cin >> N >> K >> C; vector> WPUV(K); for(auto &[w,p,u,v] : WPUV) cin >> u >> v >> w >> p,u--,v--; sort(WPUV.begin(),WPUV.end()); int answer = 0; long long cost = 0; UnionFind UF; UF.make(N); vector>> Graph(N); for(int i=0; i C){cout << -1 << endl; return 0;} LowestCommonAncestor Z; Z.make(Graph,0); for(int i=0; i