105942024-04-06 12:18:41Valaki2Drónfutárcpp17Runtime error 15/100104ms66356 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 1e5;

struct edge {
    int a, b;
    int wei;
    bool operator < (const edge & other) const {
        return wei < other.wei;
    }
};

int n;
int x[1 + maxn], y[1 + maxn];

int par[1 + maxn];
int sz[1 + maxn];

void create_set(int a) {
    par[a] = a;
    sz[a] = 1;
}

int find_set(int a) {
    if(a == par[a]) {
        return a;
    }
    return find_set(par[a]);
}

bool union_sets(int a, int b) {
    a = find_set(a), b = find_set(b);
    if(a == b) {
        return false;
    }
    if(sz[a] > sz[b]) {
        swap(a, b);
    }
    sz[b] += sz[a];
    par[a] = b;
    return true;
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    vector<edge> edges;
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            edges.pb(edge {i, j, abs(x[i] - x[j]) + abs(y[i] - y[j])});
        }
    }
    sort(edges.begin(), edges.end());
    for(int i = 1; i <= n; i++) {
        create_set(i);
    }
    int ans = 0;
    for(edge e : edges) {
        if(union_sets(e.a, e.b)) {
            ans = max(ans, e.wei);
        }
    }
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1844 KiB
2Runtime error94ms66356 KiB
subtask215/15
3Accepted90ms27084 KiB
4Accepted90ms27232 KiB
5Accepted94ms27508 KiB
6Accepted90ms27756 KiB
7Accepted14ms9672 KiB
subtask30/15
8Accepted90ms27084 KiB
9Accepted90ms27232 KiB
10Accepted94ms27508 KiB
11Accepted90ms27756 KiB
12Accepted14ms9672 KiB
13Accepted48ms28292 KiB
14Accepted104ms28532 KiB
15Accepted103ms28792 KiB
16Accepted104ms28784 KiB
17Accepted100ms28812 KiB
subtask40/35
18Accepted90ms27084 KiB
19Accepted90ms27232 KiB
20Accepted94ms27508 KiB
21Accepted90ms27756 KiB
22Accepted14ms9672 KiB
23Accepted48ms28292 KiB
24Accepted104ms28532 KiB
25Accepted103ms28792 KiB
26Accepted104ms28784 KiB
27Accepted100ms28812 KiB
28Accepted104ms28784 KiB
29Runtime error59ms64296 KiB
30Runtime error61ms64296 KiB
31Runtime error61ms64204 KiB
32Runtime error57ms64208 KiB
subtask50/35
33Accepted90ms27084 KiB
34Accepted90ms27232 KiB
35Accepted94ms27508 KiB
36Accepted90ms27756 KiB
37Accepted14ms9672 KiB
38Accepted48ms28292 KiB
39Accepted104ms28532 KiB
40Accepted103ms28792 KiB
41Accepted104ms28784 KiB
42Accepted100ms28812 KiB
43Accepted104ms28784 KiB
44Runtime error59ms64296 KiB
45Runtime error61ms64296 KiB
46Runtime error61ms64204 KiB
47Runtime error57ms64208 KiB
48Runtime error67ms63996 KiB
49Runtime error92ms63968 KiB
50Runtime error79ms63688 KiB
51Runtime error92ms63432 KiB
52Runtime error79ms63460 KiB