// Using Union-find struct edge{ int u,v,w; }; bool Kruskal_cmp(const edge *a, const edge *b) { return a->ww; } // Return -1 if no tree found. int Kruskal(int n, int m, edge e[], int ret[]) { if(n==1) return 0; static edge *d[maxm]; for(int i=0; iu) != find(f, d[i]->v)) { unite(f,d[i]->u,d[i]->v); c+=d[i]->w; ret[j]=d[i]-e; if(++j==n-1) return c; } return -1; }