intkruskal(vector<Edge> edges, int N, int M){ sort(edges.begin(), edges.end(), edgesCmp); FindUnionSet set = FindUnionSet(N); int minCost = 0; int i = 0; int k = 0; while (i < N - 1) { if (set.find(edges[k].a) != set.find(edges[k].b)) { set.unionset(edges[k].a, edges[k].b); minCost += edges[k].length; i++; } k++; }
return minCost; }
intmain(){ int N = 0, M = 0; cin >> N >> M; vector<Edge> edges = vector<Edge>(M); for (int i = 0; i < M; i++) { int a = 0, b = 0, edge = 0; cin >> a >> b >> edge; edges[i].a = a; edges[i].b = b; edges[i].length = edge; }