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

const int N = 100005;

int q, m, n, dsu[2 * N];
long long ans = 0;
bool vis[2 * N];

struct SQuery {
    int v, x, y;
} a[N];

int trace(int u) {
    return dsu[u] < 0 ? u : dsu[u] = trace(dsu[u]);
}

bool connect(int u, int v) {
    u = trace(u); v = trace(v);
    if (vis[u] && vis[v]) {
        return false;
    }
    if (u == v) {
        vis[u] = true;
    } else {
        if (dsu[u] > dsu[v]) {
            swap(u, v);
        }
        dsu[u] += dsu[v];
        vis[u] |= vis[v];
        dsu[v] = u;
    }
    return true;
}

int main() {
    cin >> q >> m >> n;
    for (int i = 1; i <= q; i++) {
        cin >> a[i].x >> a[i].y >> a[i].v;
        a[i].y += m;
    }
    fill(dsu + 1, dsu + m + n + 1, -1);
    sort(a + 1, a + q + 1, [](const SQuery &a, const SQuery &b) {
        return a.v > b.v;
    });
    for (int i = 1; i <= q; i++) {
        if (connect(a[i].x, a[i].y)) {
            ans += a[i].v;
        }
    }
    cout << ans;
}
