#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int m;
int q;
int p[N];
vector < int > v[N], backup;
bool used[N];

bool dfs(int x)
{
        used[x] = true;
        backup.push_back(x);
        for(int y: v[x]){
                if(p[y] == -1){
                        p[y] = x;
                        return true;
                } else if(!used[p[y]] && dfs(p[y])){
                        p[y] = x;
                        return true;
                }
        }
        return false;
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> q >> n >> m;
        for(int i = 1; i <= n + m; i++){
                p[i] = -1;
        }
        vector < pair < int, int > > qu;
        for(int i = 1; i <= q; i++){
                int x, y, w;
                cin >> x >> y >> w;
                v[i].push_back(x);
                v[i].push_back(y + n);
                qu.push_back({w, i});

                shuffle(v[i].begin(), v[i].end(), rng);
        }
        sort(qu.begin(), qu.end());
        reverse(qu.begin(), qu.end());
        long long res = 0;
        for(auto g: qu){
                if(dfs(g.se)){
                        res += g.fi;
                        while(!backup.empty()){
                                used[backup.back()] = false;
                                backup.pop_back();
                        }
                }
        }
        cout << res << "\n";
}
