(kruskalmst) #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;irank[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<=edgecount;i++) { int a,b,weight; cin>>a>>b>>weight; edgelist.push_back({weight,a,b}); } sort(edgelist.begin(),edgelist.end()); dsu s(nodecount); kruskals_mst(edgelist,s); return 0; }