33362023-02-26 12:10:57zsomborMobilNet (50 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/04ms4784 KiB
2Elfogadva0/012ms6088 KiB
3Elfogadva2/24ms5076 KiB
4Elfogadva2/24ms5048 KiB
5Elfogadva2/24ms5304 KiB
6Elfogadva2/24ms5256 KiB
7Elfogadva2/24ms5388 KiB
8Elfogadva2/26ms5968 KiB
9Elfogadva2/26ms6156 KiB
10Elfogadva2/28ms6808 KiB
11Elfogadva2/210ms7028 KiB
12Elfogadva2/216ms8072 KiB
13Elfogadva3/323ms8852 KiB
14Elfogadva3/332ms9280 KiB
15Elfogadva3/343ms11788 KiB
16Elfogadva3/350ms11988 KiB
17Elfogadva3/371ms14456 KiB
18Elfogadva3/365ms11812 KiB
19Elfogadva3/379ms14364 KiB
20Elfogadva3/397ms12928 KiB
21Elfogadva3/3104ms18224 KiB
22Elfogadva3/3101ms18192 KiB