#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

typedef pair <int, int> pii;
typedef pair <int, pii> piii;

piii a[100010];
int fa[200010], size[200010];

int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}

void merge(int x, int y) {
	size[x] += size[y], fa[y] = x;
}

bool check(int x, int y) {
	x = find(x), y = find(y);
	if (x != y) merge(x, y);
	if (size[x]) {
		size[x]--;
		return 1;
	}
	return 0;
}

int main() {
	int n, h, w; scanf("%d%d%d", &n, &h, &w);
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d", &a[i].se.fi, &a[i].se.se, &a[i].fi);
		a[i].se.se += h;
	}
	sort(a, a + n), reverse(a, a + n);
	for (int i = 1; i <= h + w; i++) {
		fa[i] = i, size[i] = 1;
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (check(a[i].se.fi, a[i].se.se)) ans += a[i].fi;
	}
	printf("%lld\n", ans);
	return 0;
}
