#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n, h, w;
pair<int,pii> pts[125252];

int dat[252521];
int cnt[252521];
int root(int x){
    return dat[x]<0?x:dat[x]=root(dat[x]);
}
void unite(int a, int b){
    a=root(a);b=root(b);
    if(a==b)return;
    if(dat[a]>dat[b])swap(a,b);
    dat[a] += dat[b];
    dat[b] = a;
    cnt[a] += cnt[b];
}

int main(){
    scanf("%d%d%d",&n,&h,&w);
    REP(i,n){
        int r,c,a;
        scanf("%d%d%d",&r,&c,&a);
        --r;--c;
        pts[i] = make_pair(a,pii(r,c));
    }
    sort(pts,pts+n);
    reverse(pts,pts+n);
    fill(dat,dat+(h+w),-1);
    fill(cnt,cnt+(h+w),1);
    ll ans = 0;
    REP(i,n){
        int r,c,a;
        a = pts[i].first;
        tie(r,c) = pts[i].second;
        r = root(r);
        c = root(c+h);
        if(cnt[r]>0 || cnt[c]>0){
            unite(r,c);
            ans += a;
            r = root(r);
            cnt[r]--;
        }
    }
    printf("%lld\n",ans);
    return 0;
}
