160892025-03-30 21:00:29szilVárosokcpp17Accepted 100/10041ms3092 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 50001;

vector<int> g[MAXN];
int vis[MAXN];
int mt[MAXN];

bool try_kuhn(int u, int iter) {
    if (vis[u] == iter) return false;
    vis[u] = iter;
    for (int v : g[u]) {
        if (mt[v] == -1 || try_kuhn(mt[v], iter)) {
            mt[v] = u;
            return true;
        }
    }
    return false;
}

void solve() {
    int n; ll a, b; cin >> n >> a >> b;
    fill(mt, mt+MAXN, -1);
    vector<pair<int, int>> v(n);
    for (auto &[x, y] : v) cin >> x >> y;
    vector<int> comp_x, comp_y;
    for (auto [x, y] : v) {
        comp_x.emplace_back(x);
        comp_y.emplace_back(y);
    }
    sort(comp_x.begin(), comp_x.end());
    sort(comp_y.begin(), comp_y.end());
    comp_x.erase(unique(comp_x.begin(), comp_x.end()), comp_x.end());
    comp_y.erase(unique(comp_y.begin(), comp_y.end()), comp_y.end());
    for (auto &[x, y] : v) {
        x = lower_bound(comp_x.begin(), comp_x.end(), x) - comp_x.begin();
        y = lower_bound(comp_y.begin(), comp_y.end(), y) - comp_y.begin();
        g[x].emplace_back(y);
    }

    int flow = 0;
    for (int i = 0; i < comp_x.size(); i++) {
        flow += try_kuhn(i, i+1);
    }

    ll cnt1 = comp_x.size() + comp_y.size();
    ll cnt2 = comp_x.size() + comp_y.size() - flow;

    ll ans = cnt1 * b + cnt2 * a;
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1; 
    // cin >> t;
    while (t--) solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1588 KiB
2Accepted2ms1784 KiB
subtask210/10
3Accepted2ms1792 KiB
4Accepted2ms1588 KiB
5Accepted2ms1588 KiB
6Accepted2ms1588 KiB
subtask35/5
7Accepted39ms2996 KiB
8Accepted9ms2284 KiB
9Accepted39ms2992 KiB
10Accepted41ms2992 KiB
11Accepted39ms3092 KiB
subtask440/40
12Accepted6ms2028 KiB
13Accepted37ms2992 KiB
14Accepted35ms2992 KiB
15Accepted35ms2988 KiB
16Accepted6ms1844 KiB
17Accepted35ms2992 KiB
18Accepted32ms2752 KiB
19Accepted14ms2376 KiB
20Accepted26ms2728 KiB
21Accepted8ms2104 KiB
subtask545/45
22Accepted39ms2992 KiB
23Accepted39ms2992 KiB
24Accepted32ms2736 KiB
25Accepted32ms2744 KiB
26Accepted39ms2996 KiB
27Accepted39ms2992 KiB