33352023-02-26 12:02:35zsomborMobilNet (50 pont)cpp17Wrong answer 8/50104ms18740 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();
        if (HOLVAN(a) == HOLVAN(b)) continue;
        if (w > t) { t = w; prevk = k; }
        UNIO(a, b);
        if (k == 1) break;
    }
    cout << t << endl << prevk - 1;
}
SubtaskSumTestVerdictTimeMemory
base8/50
1Accepted0/04ms4912 KiB
2Wrong answer0/010ms6008 KiB
3Wrong answer0/24ms5204 KiB
4Accepted2/24ms5424 KiB
5Partially correct1/24ms5372 KiB
6Partially correct1/24ms5504 KiB
7Partially correct1/24ms5632 KiB
8Partially correct1/24ms6212 KiB
9Wrong answer0/26ms6424 KiB
10Wrong answer0/28ms7184 KiB
11Wrong answer0/210ms7516 KiB
12Wrong answer0/216ms8516 KiB
13Wrong answer0/324ms9600 KiB
14Wrong answer0/332ms10232 KiB
15Partially correct2/343ms12612 KiB
16Wrong answer0/350ms12616 KiB
17Wrong answer0/371ms15104 KiB
18Wrong answer0/359ms12464 KiB
19Wrong answer0/378ms14788 KiB
20Wrong answer0/387ms13624 KiB
21Wrong answer0/3104ms18712 KiB
22Wrong answer0/3101ms18740 KiB