#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,H,W;

template<class V> class MaxFlow_dinic {
public:
	struct edge { int to,reve;V cap;};
	static const int MV = 301100;
	vector<edge> E[MV];
	int itr[MV],lev[MV];
	void add_edge(int x,int y,V cap,bool undir=false) {
		E[x].push_back((edge){y,(int)E[y].size(),cap});
		E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0});
	}
	void bfs(int cur) {
		MINUS(lev);
		queue<int> q;
		lev[cur]=0;
		q.push(cur);
		while(q.size()) {
			int v=q.front(); q.pop();
			ITR(e,E[v]) if(e->cap>0 && lev[e->to]<0) lev[e->to]=lev[v]+1, q.push(e->to);
		}
	}
	V dfs(int from,int to,V cf) {
		if(from==to) return cf;
		for(;itr[from]<E[from].size();itr[from]++) {
			edge* e=&E[from][itr[from]];
			if(e->cap>0 && lev[from]<lev[e->to]) {
				V f=dfs(e->to,to,min(cf,e->cap));
				if(f>0) {
					e->cap-=f;
					E[e->to][e->reve].cap += f;
					return f;
				}
			}
		}
		return 0;
	}
	V maxflow(int from, int to) {
		V fl=0,tf;
		while(1) {
			bfs(from);
			if(lev[to]<0) return fl;
			ZERO(itr);
			while((tf=dfs(from,to,numeric_limits<V>::max()))>0) fl+=tf;
		}
	}
};
MaxFlow_dinic<ll> mf;

int R[101010],C[101010],A[101010];
int Rok[101010],Cok[101010];
set<int> RE[101010];
set<int> CE[101010];
void dfsC(int x);

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<202020> uf;

void dfsR(int y) {
	Rok[y]=0;
	while(RE[y].size()) {
		int x=*RE[y].begin();
		RE[y].erase(RE[y].begin());
		CE[x].erase(y);
		dfsC(x);
	}
}
void dfsC(int x) {
	Cok[x]=0;
	while(CE[x].size()) {
		int y=*CE[x].begin();
		CE[x].erase(CE[x].begin());
		RE[y].erase(x);
		dfsR(y);
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>H>>W;
	vector<vector<int>> V;
	FOR(i,N) {
		cin>>R[i]>>C[i]>>A[i];
		R[i]--;
		C[i]--;
		V.push_back({A[i],R[i],C[i]});
	}
	FOR(i,H) Rok[i]=1;
	FOR(i,W) Cok[i]=1;
	
	sort(ALL(V));
	reverse(ALL(V));
	ll ret=0;
	FORR(v,V) {
		int y=v[1];
		int x=v[2];
		
		if(Rok[y]&&Cok[x]) {
			if(uf[y]==uf[x+100000]) {
				dfsR(y);
				dfsC(x);
			}
			else {
				uf(y,x+100000);
				RE[y].insert(x);
				CE[x].insert(y);
			}
			ret+=v[0];
		}
		else if(Rok[y]) {
			dfsR(y);
			ret+=v[0];
		}
		else if(Cok[x]) {
			dfsC(x);
			ret+=v[0];
		}
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 41648