for(int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; a--; b--; edges.push({a, b, c}); }
vector<int> parent(n); for (int i = 0; i < n; ++i) parent[i] = i;
int edgeCount = 0, total = 0; while (!edges.empty()) { Edge nextEdge = edges.top(); // cout << "Get an edge with src=" << nextEdge.src << ", dst=" << nextEdge.dest << ", wgt=" << nextEdge.weight << endl; edges.pop(); int x = find(parent, nextEdge.src); int y = find(parent, nextEdge.dest); // cout << nextEdge.src << " is pointing to " << x << endl; // cout << nextEdge.dest << " is pointing to " << y << endl;
if (x != y) { // cout << "Now " << x << " is pointing to " << y << endl; parent[x] = y; total += nextEdge.weight; edgeCount++; } }
if(edgeCount == n - 1) cout << total << endl; else cout << "orz" ;//<< edgeCount << endl;