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

typedef pair <int, int> ii;
typedef long long ll;

const int Maxn = 200005;

int n, H, W;
int R[Maxn], C[Maxn], A[Maxn];
int seq[Maxn];
int par[Maxn], siz[Maxn];
bool ful[Maxn];
ll res;

bool Less(const int &a, const int &b) { return A[a] > A[b]; }

int getPar(int x) { return par[x] == x? x: par[x] = getPar(par[x]); }

bool unionSet(int a, int b)
{
    a = getPar(a), b = getPar(b);
    if (a == b)
        if (ful[a]) return false;
        else { ful[a] = true; return true; }
    else {
        if (siz[a] < siz[b]) swap(a, b);
        siz[a] += siz[b]; par[b] = a;
        if (ful[a] && ful[b]) return false;
        ful[a] |= ful[b];
        return true;
    }
}

int main()
{
    scanf("%d %d %d", &n, &H, &W);
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &R[i], &C[i], &A[i]);
        seq[i] = i;
    }
    sort(seq, seq + n, Less);
    for (int i = 1; i <= H + W; i++) {
        par[i] = i, siz[i] = 1, ful[i] = false;
    }
    for (int i = 0; i < n; i++) {
        int ind = seq[i];
        if (unionSet(R[ind], H + C[ind]))
            res += A[ind];
    }
    cout << res << endl;
    return 0;
}
