56742023-09-07 17:18:30TuruTamasMobilNet (50 pont)cpp17Forditási hiba
//
// Created by tamas on 9/7/23.
//

// sztem kicsit ronda, de hát na

#include "bits/stdc++.h"
using namespace std;

#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define ull unsigned long long

int N;
ull top, bot, T;

typedef pair<ull, ull> coord;

vector<coord> by_x;
vector<coord> by_y;
map<coord, bool> visited;

auto sort_by_x = [](coord a, coord b) {
    if (a.first == b.first)
        return a.second > b.second;
    return a.first < b.first;
};

auto sort_by_y = [](coord a, coord b) {
    if (a.second == b.second)
        return a.first > b.first;
    return a.second > b.second;
};

void dfs(coord& x) {
//    cout << "in " << x.first << " " << x.second << "\n";
    visited[x] = true;
    long ind = std::lower_bound(by_x.begin(), by_x.end(), x, sort_by_x) - by_x.begin();
    long i = ind-1;
    while (i >= 0 && by_x[i].first == x.first && by_x[i].second - x.second <= T) {
        if (!visited[by_x[i]]) {
            dfs(by_x[i]);
        }
        i--;
    }
    i = ind+1;
    while (i < N && by_x[i].first == x.first && x.second - by_x[i].second <= T) {
        if (!visited[by_x[i]]) {
            dfs(by_x[i]);
        }
        i++;
    }

    ind = std::lower_bound(by_y.begin(), by_y.end(), x, sort_by_y) - by_y.begin();
    i = ind-1;
    while (i >= 0 && by_y[i].second == x.second && by_y[i].first - x.first <= T) {
        if (!visited[by_y[i]]) {
            dfs(by_y[i]);
        }
        i++;
    }
    i = ind+1;
    while (i < N && by_y[i].second == x.second && x.first - by_y[i].first <= T ) {
        if (!visited[by_y[i]]) {
            dfs(by_y[i]);
        }
        i--;
    }
}

bool good() {
    for (auto& kv : visited) {
        kv.second = false;
    }
//    cout << "T=" << T << ":\n";
    dfs(by_x[0]);
    bool r = true;
    for (auto p : visited)
        if (!p.second)
            r = false;
    return r;
}

int gut() {
    for (auto& kv : visited) {
        kv.second = false;
    }
//    cout << "T=" << T << ":\n";
    int r = -1;
    T--;
    for (auto p : visited)
        if (!p.second) {
            r++;
            dfs(p.first);
        }
    T++;
    return r;
}

int main() {
    InTheNameOfGod
    cin >> N;
    for (int i = 0; i < N; i++) {
        ull x, y;
        cin >> x >> y;
        x--; y--;
        visited.emplace(make_pair(x, y), false);
        by_x.emplace_back(x, y);
        by_y.emplace_back(x, y);
    }
    std::sort(by_y.begin(), by_y.end(), sort_by_y);
    std::sort(by_x.begin(), by_x.end(), sort_by_x);
    bot = 1;
    top = 10'000'001;
    T = (bot + top) / 2;
    while (bot != top) {
        if (good())
            top = T - 1;
        else
            bot = T + 1;
        T = (bot + top) / 2;
    }
    cout << T << "\n" << gut();
}
Forditási hiba
exit status 1
main.cpp: In function 'int gut()':
main.cpp:93:19: error: binding reference of type 'coord&' {aka 'std::pair<long long unsigned int, long long unsigned int>&'} to 'const std::pair<long long unsigned int, long long unsigned int>' discards qualifiers
   93 |             dfs(p.first);
      |                 ~~^~~~~
main.cpp:34:17: note:   initializing argument 1 of 'void dfs(coord&)'
   34 | void dfs(coord& x) {
      |          ~~~~~~~^
Exited with error status 1