#include using namespace std; int nodecount,edgecount; class DSU{ int*parent; int* rank; public: DSU(int n) { parent = new int[n]; rank = new int[n]; for (int i=0;i rank [s2]){ parent[s2]=s1; } else { parent[s2]=s1; rank[s1]+=1; } } } }; void kruskals_mst(vector>G,DSU s){ int ans=0; for(auto edge:G){ int W =edge[0]; int x=edge[1]; int y=edge[2]; if (s.find(x)!=s.find(y)){ s.union(x,y); ans+=w; cout<>edgelist; cin>>nodecount>>edgecount; for(int i=1;i>a>>b>>weight; edgelist.push_back({weight,a,b}); } sort(edgelist.begin(),edgelist.end()); DSU s(nodecount); kruskal_mst(edgelist,s); return 0; }