#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;




int cap[maxn];
int siz[maxn];
int par[maxn];


int parent(int x) {
    if (x==par[x]) return x;
    return par[x]=parent(par[x]);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    int n, h, w;
    cin>>n>>h>>w;

    for (int i=0; i<h+w; i++) {
	cap[i] = 1;
	siz[i] = 1;
	par[i] = i;
    }
    
    
    vector<pair<ll,pair<int,int>>> cards;
    for (int i=0; i<n; i++) {
	int r,c,a;
	cin>>r>>c>>a;
	--r; --c;
	cards.push_back({a,{r,c}});
    }

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


    ll res = 0;

    while (!cards.empty()) {
	auto card = cards.back();
	ll val = card.first;
	int r = card.second.first;
	int c = card.second.second + h;
	cards.pop_back();

	r = parent(r);
	c = parent(c);

	if (r==c) {
	    if (cap[r] >= 1) {
		res += val;
		cap[r]--;
	    }
	} else {
	    if (cap[r]+cap[c] >= 1) {
		res += val;
		if (siz[r] < siz[c]) {
		    swap(r, c);
		}
		siz[r] += siz[c];
		par[c] = r;
		cap[r] += cap[c];
		cap[r]--;
	    }
	}
    }

    cout<<res<<endl; 
    return 0;
}
