61592023-11-04 00:11:40horvathabelMobilNet (50 pont)cpp17Runtime error 44/50257ms62668 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;
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++;
        p[b]=a;
    }
}
vector<node> g;
bool r(node a, node b){
return (a.w<b.w) ;
}

int main()
{
    int n;
    cin>>n;
    map<ll,vector<pair<ll,ll>>> xk;
    map<ll,vector<pair<ll,ll>>> yk;

    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_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 && i<g.size()){
        unio(g[i].a,g[i].b,g[i].w);
        i++;
    }
    cout<<maxw<<"\n";
    cout<<ans;
}
SubtaskSumTestVerdictTimeMemory
base44/50
1Accepted0/03ms3096 KiB
2Accepted0/016ms5708 KiB
3Accepted2/23ms3684 KiB
4Accepted2/23ms3896 KiB
5Accepted2/23ms4104 KiB
6Accepted2/24ms4300 KiB
7Accepted2/24ms4636 KiB
8Accepted2/24ms5092 KiB
9Accepted2/28ms5776 KiB
10Accepted2/29ms6420 KiB
11Accepted2/213ms6912 KiB
12Accepted2/218ms8164 KiB
13Accepted3/332ms10908 KiB
14Accepted3/361ms20976 KiB
15Accepted3/3149ms34532 KiB
16Accepted3/390ms22864 KiB
17Accepted3/3114ms25996 KiB
18Runtime error0/383ms62668 KiB
19Accepted3/3257ms60392 KiB
20Runtime error0/386ms62620 KiB
21Accepted3/3188ms37788 KiB
22Accepted3/3193ms37872 KiB