long int kruskal(int m, vector<triple> &arestas){

	DisjointSet<int> *ds = new DisjointSet<int>(m);
	// vector<ii> result;
	long int t = 0;

	for(int i=0; i<m; i++)
		ds->make(i, 0);

	sort(arestas.begin(), arestas.end());

	int e = 0, i = 0;
	while(e < m-1){

		int u = ds->find(arestas[i].first);
		int v = ds->find(arestas[i].second);

		if(ds->find(u) != ds->find(v)){
			t += arestas[i].third;
			// result.push_back(ii(u, v));
			ds->join(u, v);
			e++;
		}

		i++;
	}

	return t;
}
Esempio n. 2
0
inline
int kruskal(Edge E[], const int size)
{
  static DisjointSet ds;
  int cnt = 0, sum = 0;
  REP(i, size){
    ds.make(i);
  }