238172026-01-30 12:08:45algoproMobilNet (50 pont)cpp17Accepted 50/5050ms3188 KiB
// UUID: fef917ba-3329-49bf-8487-32bb383f4a48
#include <bits/stdc++.h>
using namespace std;

vector<int> rep, s;

void unite(int u, int v) {
    if (s[u] < s[v]) swap(u, v);
    rep[v] = u;
    s[u] += s[v];
}

int fnd(int node) {
    if (rep[node] == node) return node;
    return rep[node] = fnd(rep[node]);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    rep.resize(n);
    s.assign(n, 1);
    vector<pair<pair<int, int>, int>> a(n);
    for (int i = 0; i < n; i++) {
        rep[i] = a[i].second = i;
        cin >> a[i].first.first >> a[i].first.second;
    }
    vector<pair<int, pair<int, int>>> edges;
    sort(a.begin(), a.end());
    for (int i = 1; i < n; i++) if (a[i].first.first == a[i - 1].first.first) edges.push_back({a[i].first.second - a[i - 1].first.second, {a[i].second, a[i - 1].second}});
    for (int i = 0; i < n; i++) swap(a[i].first.first, a[i].first.second);
    sort(a.begin(), a.end());
    for (int i = 1; i < n; i++) if (a[i].first.first == a[i - 1].first.first) edges.push_back({a[i].first.second - a[i - 1].first.second, {a[i].second, a[i - 1].second}});
    sort(edges.begin(), edges.end());
    int mx = 0, cnt = 0;
    for (int i = 0; i < edges.size(); i++) {
        int u = fnd(edges[i].second.first), v = fnd(edges[i].second.second);
        if (u == v) continue;
        if (mx < edges[i].first) {
            mx = edges[i].first;
            cnt = 0;
        }
        cnt++;
        unite(u, v);
    }
    cout << mx << "\n" << cnt;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms508 KiB
2Accepted0/04ms564 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/22ms508 KiB
7Accepted2/22ms508 KiB
8Accepted2/21ms324 KiB
9Accepted2/22ms316 KiB
10Accepted2/23ms564 KiB
11Accepted2/24ms568 KiB
12Accepted2/26ms796 KiB
13Accepted3/38ms980 KiB
14Accepted3/314ms1236 KiB
15Accepted3/317ms1292 KiB
16Accepted3/323ms1840 KiB
17Accepted3/329ms1844 KiB
18Accepted3/335ms2868 KiB
19Accepted3/339ms2988 KiB
20Accepted3/350ms3176 KiB
21Accepted3/345ms3188 KiB
22Accepted3/341ms3132 KiB