33362023-02-26 12:10:57zsomborMobilNet (50 pont)cpp17Accepted 50/50104ms18224 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int n, t = 0, k, prevk;
vector <int> X(1e5);
vector <int> Y(1e5);
map <int, vector <pair <int, int>>> mX;
map <int, vector <pair <int, int>>> mY;
priority_queue <pair <int, pair <int, int>>> pq;

vector <int> p(1e5);
vector <int> sz(1e5, 1);

int HOLVAN(int a) {
    if (a == p[a]) return a;
    return p[a] = HOLVAN(p[a]);
}

void UNIO(int a, int b) {
    if (sz[a] < sz[b]) swap(a, b);
    p[b] = a;
    sz[a] += sz[b];
    k--;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> X[i] >> Y[i];
        mX[X[i]].push_back({ Y[i],i });
        mY[Y[i]].push_back({ X[i],i });
    }
    int a, b, w;
    for (auto p : mX) {
        vector<pair<int, int>>& v = p.second;
        sort(v.begin(), v.end());
        for (int j = 1; j < v.size(); j++) {
            a = v[j - 1].second;
            b = v[j].second;
            w = v[j].first - v[j - 1].first;
            pq.push({ -w,{a,b} });
        }
    }
    for (auto p : mY) {
        vector<pair<int, int>>& v = p.second;
        sort(v.begin(), v.end());
        for (int j = 1; j < v.size(); j++) {
            a = v[j - 1].second;
            b = v[j].second;
            w = v[j].first - v[j - 1].first;
            pq.push({ -w,{a,b} });
        }
    }
    k = n;
    for (int i = 0; i < n; i++) p[i] = i;
    while (pq.size()) {
        a = pq.top().second.first;
        b = pq.top().second.second;
        w = -pq.top().first;
        pq.pop();
        a = HOLVAN(a);
        b = HOLVAN(b);
        if (a == b) continue;
        if (w > t) { t = w; prevk = k; }
        UNIO(a, b);
        if (k == 1) break;
    }
    cout << t << endl << prevk - 1;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/04ms4784 KiB
2Accepted0/012ms6088 KiB
3Accepted2/24ms5076 KiB
4Accepted2/24ms5048 KiB
5Accepted2/24ms5304 KiB
6Accepted2/24ms5256 KiB
7Accepted2/24ms5388 KiB
8Accepted2/26ms5968 KiB
9Accepted2/26ms6156 KiB
10Accepted2/28ms6808 KiB
11Accepted2/210ms7028 KiB
12Accepted2/216ms8072 KiB
13Accepted3/323ms8852 KiB
14Accepted3/332ms9280 KiB
15Accepted3/343ms11788 KiB
16Accepted3/350ms11988 KiB
17Accepted3/371ms14456 KiB
18Accepted3/365ms11812 KiB
19Accepted3/379ms14364 KiB
20Accepted3/397ms12928 KiB
21Accepted3/3104ms18224 KiB
22Accepted3/3101ms18192 KiB