61602023-11-04 00:19:44horvathabelMobilNet (50 pont)cpp17Runtime error 44/50165ms63044 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll cnt=0;
vector<ll> p(100001,-1);
ll maxw=0;
ll ans=0;


ll holvan(ll a){
    if (p[a]==-1) return a;
    return p[a]=holvan(p[a]);
}
void unio(ll a,ll b, ll w){
    a=holvan(a);
    b=holvan(b);
    if (a!=b){
        cnt++;
        if (w>maxw){
            maxw=w;
            ans=0;
        }
        if (w==maxw) ans++;
        p[b]=a;
    }
}

int main()
{
    int n;
    cin>>n;
    map<ll,vector<pair<ll,ll>>> xk;
    map<ll,vector<pair<ll,ll>>> yk;
    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> g;
    for (int i=0; i<n;i++){
        ll x,y;
        cin>>x>>y;
        yk[y].push_back({x,i});
        xk[x].push_back({y,i});
        for (pair<int,int> a:xk[x]){
            if (i!=a.second) g.push({abs(y-a.first),{i,a.second}});
        }
        for (pair<int,int> a:yk[y]){
            if (i!=a.second)  g.push({abs(x-a.first),{i,a.second}});
        }

    }
    ll i=0;
    while (cnt<n-1 && !g.empty()){
        pair<int,pair<int,int>> v=g.top();
        g.pop();
        unio(v.second.first,v.second.second,v.first);
        i++;
    }
    cout<<maxw<<"\n";
    cout<<ans;
}
SubtaskSumTestVerdictTimeMemory
base44/50
1Accepted0/03ms3104 KiB
2Accepted0/016ms5236 KiB
3Accepted2/23ms3416 KiB
4Accepted2/24ms3676 KiB
5Accepted2/23ms3976 KiB
6Accepted2/24ms4268 KiB
7Accepted2/24ms4200 KiB
8Accepted2/24ms4912 KiB
9Accepted2/28ms5292 KiB
10Accepted2/29ms5596 KiB
11Accepted2/213ms6208 KiB
12Accepted2/218ms7444 KiB
13Accepted3/332ms9452 KiB
14Accepted3/363ms14716 KiB
15Accepted3/379ms22972 KiB
16Accepted3/379ms16768 KiB
17Accepted3/3112ms19520 KiB
18Runtime error0/3136ms63044 KiB
19Accepted3/3157ms35404 KiB
20Runtime error0/3143ms63020 KiB
21Accepted3/3165ms25364 KiB
22Accepted3/3153ms25432 KiB