#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+1000;
struct node{
	int c,r;
	LL x;
}a[N];
bool cmp(node a,node b){
	return a.x>b.x;
}
int fa[N],g[N];
int find(int x){
	return fa[x]==x?x:(fa[x]=find(fa[x]));
}
bool merge(int x,int y){
	x=find(x);y=find(y);
	cout<<x<<" "<<g[x]<<"   "<<y<<" "<<g[y]<<endl;
	if(x==y){
		if(g[x])return 0;
		else return g[x]=1;
	}
	if(g[x]&&g[y])return 0;
	fa[y]=x;
	g[x]|=g[y];
	return 1;
}

int main()
{
	LL ans=0;
	int n,h,w;
	scanf("%d%d%d",&n,&h,&w);
	for(int i=1;i<=n;i++){
		scanf("%d%d%lld",&a[i].r,&a[i].c,&a[i].x);
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=h+w;i++)fa[i]=i,g[i]=0;
	for(int i=1;i<=n;i++){
		if(merge(a[i].r,a[i].c+h))ans+=a[i].x;
		
	}
	printf("%lld\n",ans);
}