61552023-11-04 00:04:10horvathabelMobilNet (50 pont)cpp17Runtime error 44/50270ms63260 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll cnt=0;
vector<ll> p;
vector<ll> siz;
ll maxw=0;
ll ans=0;
struct node{
    ll a;
    ll b;
    ll w;

};

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++;
        if (siz[a]>siz[b]){
            siz[a]++;
            p[b]=a;
            return;
        }
        siz[b]++;
        p[a]=b;
    }
}
vector<node> g;
bool r(node a, node b){
return (a.w<b.w) ;
}

int main()
{
    int n;
    cin>>n;
    p.resize(n+1,-1);
    siz.resize(n+1,1);
    vector<pair<ll, ll>> z;
    map<int,vector<pair<int,int>>> xk;
    map<int,vector<pair<int,int>>> yk;

    for (int i=0; i<n;i++){
        ll x,y;
        cin>>x>>y;
        z.push_back({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_back({i,a.second,abs(y-a.first)});
        }
        for (pair<int,int> a:yk[y]){
            if (i!=a.second)  g.push_back({i,a.second,abs(x-a.first)});
        }

    }
    sort(g.begin(),g.end(), r);
    ll i=0;
    while (cnt<n-1){
        unio(g[i].a,g[i].b,g[i].w);
        i++;
    }
    cout<<maxw<<"\n";
    cout<<ans;
}
SubtaskSumTestVerdictTimeMemory
base44/50
1Accepted0/03ms1876 KiB
2Accepted0/016ms4476 KiB
3Accepted2/23ms2344 KiB
4Accepted2/23ms2604 KiB
5Accepted2/23ms2628 KiB
6Accepted2/23ms2800 KiB
7Accepted2/24ms3100 KiB
8Accepted2/24ms3392 KiB
9Accepted2/27ms4100 KiB
10Accepted2/28ms4372 KiB
11Accepted2/212ms4888 KiB
12Accepted2/218ms6452 KiB
13Accepted3/334ms9132 KiB
14Accepted3/361ms19808 KiB
15Accepted3/3156ms33096 KiB
16Accepted3/390ms21632 KiB
17Accepted3/3108ms25140 KiB
18Runtime error0/382ms63260 KiB
19Accepted3/3270ms59552 KiB
20Runtime error0/386ms63232 KiB
21Accepted3/3196ms37376 KiB
22Accepted3/3186ms37888 KiB