Language: C++

#include <iostream>
#include <vector>
using namespace std;
//
struct edge{int from;int to;int cost;};
struct kruskal{
	//
	bool comp(const edge &e1,const edge &e2){
		return e1.cost<e2.cost;
	}
	//
	int v,e;
	vetcor<int> par,ran;
	//
	kruskal(int n,int m){
		v=n;e=m;
		init(v);
	}
	//
	void init(int n){
		par.resize(n);
		ran.resize(n);
		for(int i=0;i<n;i++){
			par[i]=i;
			ran[i]=0;
		}
	}
	//
	int find(int x){
		if(par[x]==x){
			return x;
		}else{
			return par[x]=find(par[x]);
		}
	}
	//
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y){
			return ;
		}
		if(ran[x]<ran[y]){
			par[x]=y;
		}else{
			par[y]=x;
			if(ran[x]==ran[y]){
				ran[x]++;
			}
		}
	}
	//
	bool same(int x,int y){
		return find(x)==find(y);
	}
	//
	int cul(vector<int> es){
		sort(es.begin(),es.end(),comp);
		init(v);
		int res=0;
		for(int i=0;i<e;i++){
			edge &e=es[i];
			if(!same(e.from,e.to)){
				unite(e.from,e.to);
				res+=e.cost;
			}
		}
		return res;
	}
	//
};
//
int main(){
	int V,E;
	cin>>V>>E;
	vetcor<edge> G;
	for(int i=0;i<E;i++){
		int s,t,cost;
		G.push_back((edge){s,t,cost});
	}
	kruskal k(V,E);
	cout<<k.cul(G)<<endl;
	return 0;
}


Compiler output:
a.cc:13:9: error: 'vetcor' does not name a type
   13 |         vetcor<int> par,ran;
      |         ^~~~~~
a.cc: In member function 'void kruskal::init(int)':
a.cc:21:17: error: 'par' was not declared in this scope
   21 |                 par.resize(n);
      |                 ^~~
a.cc:22:17: error: 'ran' was not declared in this scope; did you mean 'rand'?
   22 |                 ran.resize(n);
      |                 ^~~
      |                 rand
a.cc: In member function 'int kruskal::find(int)':
a.cc:30:20: error: 'par' was not declared in this scope
   30 |                 if(par[x]==x){
      |                    ^~~
a.cc: In member function 'void kruskal::unite(int, int)':
a.cc:43:20: error: 'ran' was not declared in this scope; did you mean 'rand'?
   43 |                 if(ran[x]<ran[y]){
      |                    ^~~
      |                    rand
a.cc:44:25: error: 'par' was not declared in this scope
   44 |                         par[x]=y;
      |                         ^~~
a.cc:46:25: error: 'par' was not declared in this scope
   46 |                         par[y]=x;
      |                         ^~~
a.cc: In member function 'int kruskal::cul(std::vector<int>)':
a.cc:58:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   58 |                 sort(es.begin(),es.end(),comp);
      |                 ^~~~
      |                 short
a.cc:62:37: error: invalid initialization of reference of type 'edge&' from expression of type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   62 |                         edge &e=es[i];
      |                                     ^
a.cc: In function 'int main()':
a.cc:76:9: error: 'vetcor' was not declared in this scope
   76 |         vetcor<edge> G;
      |         ^~~~~~
a.cc:76:20: error: expected primary-expression before '>' token
   76 |         vetcor<edge> G;
      |                    ^
a.cc:76:22: error: 'G' was not declared in this scope
   76 |         vetcor<edge> G;
      |                      ^