160882025-03-30 20:53:13szilVárosokcpp17Wrong answer 5/10041ms4068 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 = 2 * comp_x.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
1Accepted2ms1784 KiB
2Wrong answer2ms1588 KiB
subtask20/10
3Accepted2ms1588 KiB
4Accepted2ms1588 KiB
5Accepted2ms1588 KiB
6Wrong answer2ms1684 KiB
subtask35/5
7Accepted41ms3976 KiB
8Accepted9ms2292 KiB
9Accepted39ms4016 KiB
10Accepted41ms4068 KiB
11Accepted39ms4016 KiB
subtask40/40
12Wrong answer6ms2040 KiB
13Wrong answer35ms3504 KiB
14Wrong answer37ms3504 KiB
15Accepted37ms3504 KiB
16Accepted6ms1844 KiB
17Wrong answer35ms3504 KiB
18Wrong answer32ms3248 KiB
19Wrong answer14ms2336 KiB
20Wrong answer26ms2992 KiB
21Accepted8ms2356 KiB
subtask50/45
22Wrong answer39ms3976 KiB
23Wrong answer39ms4016 KiB
24Wrong answer34ms3552 KiB
25Wrong answer34ms3504 KiB
26Wrong answer39ms3908 KiB
27Wrong answer41ms4016 KiB