#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

struct UnionFind{
    vector<int> nxt;
    void init(int x){
        nxt.clear();
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    inline void unite(int x,int y){
        nxt[find(y)] = find(x);
    }
};



ll N,H,W;
vector<pair<ll, pll>> arcs;
UnionFind uf;
ll vn[202020],en[202020];
ll i, j,k,ans;
int main(){
    scanf("%lld%lld%lld", &N,&H,&W);
    fornum(i,0,N){
        ll r, c, a;
        scanf("%lld%lld%lld", &r, &c, &a);
        arcs.push_back({a,{r, c}});
    }
    sort(arcs.begin(), arcs.end());
    uf.init(H + W);
    fornum(i,0,H+W){
        vn[i] = 1;
    }
    fornum(i,0,N){
        //printf("%lld:%lld\n", i, ans);
        auto arc = arcs[N - 1 - i];
        auto a = arc.first;
        auto r = arc.second.first-1;
        auto c = arc.second.second - 1 + H;
        ll vvn = vn[uf.find(r)];
        ll een = en[uf.find(r)] + 1;
        if(uf.find(r)!=uf.find(c)){
            vvn += vn[uf.find(c)];
            een += en[uf.find(c)];
        }
        if(vvn>=een){
            uf.unite(r, c);
            vn[uf.find(r)] = vvn;
            en[uf.find(r)] = een;
            ans += a;
        }
    }
    printf("%lld", ans);
    return 0;
}