#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<62;
template<int N>
class UF{
    vector<int> par;
    public:
    UF():par(N,-1){}
    int operator[](int x){return (par[x] == -1)?x:par[x] = operator[](par[x]);}
    void operator()(int x,int y){
        x = operator[](x);y = operator[](y);
        if(x > y)swap(x,y);
        par[y] = x;
    }
};
UF<200050> uf;
int main(){
    int n,h,w;
    cin>>n>>h>>w;
    vector<tuple<int,int,int>> vec;
    for(int i=0;i<n;++i){
        int r,c,a;
        cin>>r>>c>>a;
        r--;c--;
        vec.emplace_back(a,r,c);
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    vector<bool> used(200050);
    ll ret = 0ll;
    for(int i=0;i<n;++i){
        int a,r,c;
        tie(a,r,c) = vec[i];
        if(!used[uf[r]] and !used[uf[c+h]]){
            if(uf[r] == uf[c+h]){
                used[uf[r]] = true;
            }else uf(r,c+h);
            ret += a;
        } else if(!used[uf[r]]){
            used[uf[r]] = true;
            ret += a;
        } else if(!used[uf[c+h]]){
            used[uf[c+h]] = true;
            ret += a;
        }
    }
    cout << ret << endl;
    return 0;
}

