#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,h,w;
int a[100005],xx[100005],yy[100005];
multiset<pair<int,pair<int,int> > >S;
vector<int>g[2][100005];
struct ssss{
	int par[200005];
	ssss(){for(int i=1;i<=200002;i++)par[i]=i;}
	int find(int x){
		return par[x]==x?x:par[x]=find(par[x]);
	}
	void merge(int x,int y){
		int nx=find(x),ny=find(y);
		par[nx]=ny;
	}
}uf;
bool dead[2][100005];
#define kill ffweifnweoifnweoif
void kill(int op,int x){
//	cerr<<op<<" "<<x<<endl;
	dead[op][x]=1;
	for(int i=0;i<g[op][x].size();i++){
		if(dead[op^1][g[op][x][i]])continue;
		kill(op^1,g[op][x][i]);
	}
}
bool can(int x,int y){
	if(dead[0][x]&&dead[1][y])return false;
	if(dead[0][x]){
		kill(1,y);
		return true;
	}
	if(dead[1][y]){
		kill(0,x);
		return true;
	}
	if(uf.find(x)==uf.find(y+1e5)){
		kill(0,x);
	}else{
		g[0][x].push_back(y);
		g[1][y].push_back(x);
		uf.merge(x,y+1e5);
	}
	return true;
}
signed main(){
	cin>>n>>h>>w;
	for(int i=1;i<=n;i++){
		cin>>xx[i]>>yy[i]>>a[i];
		S.insert(make_pair(-a[i],make_pair(xx[i],yy[i])));
	}
	int ans=0;
	while(!S.empty()){
		if(can(S.begin()->second.first,S.begin()->second.second)){
			ans-=S.begin()->first;
		}
		S.erase(S.begin());
	}
	cout<<ans<<endl;
	return 0;
}