#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();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1844 KiB | ||||
2 | Runtime error | 94ms | 66356 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 90ms | 27084 KiB | ||||
4 | Accepted | 90ms | 27232 KiB | ||||
5 | Accepted | 94ms | 27508 KiB | ||||
6 | Accepted | 90ms | 27756 KiB | ||||
7 | Accepted | 14ms | 9672 KiB | ||||
subtask3 | 0/15 | ||||||
8 | Accepted | 90ms | 27084 KiB | ||||
9 | Accepted | 90ms | 27232 KiB | ||||
10 | Accepted | 94ms | 27508 KiB | ||||
11 | Accepted | 90ms | 27756 KiB | ||||
12 | Accepted | 14ms | 9672 KiB | ||||
13 | Accepted | 48ms | 28292 KiB | ||||
14 | Accepted | 104ms | 28532 KiB | ||||
15 | Accepted | 103ms | 28792 KiB | ||||
16 | Accepted | 104ms | 28784 KiB | ||||
17 | Accepted | 100ms | 28812 KiB | ||||
subtask4 | 0/35 | ||||||
18 | Accepted | 90ms | 27084 KiB | ||||
19 | Accepted | 90ms | 27232 KiB | ||||
20 | Accepted | 94ms | 27508 KiB | ||||
21 | Accepted | 90ms | 27756 KiB | ||||
22 | Accepted | 14ms | 9672 KiB | ||||
23 | Accepted | 48ms | 28292 KiB | ||||
24 | Accepted | 104ms | 28532 KiB | ||||
25 | Accepted | 103ms | 28792 KiB | ||||
26 | Accepted | 104ms | 28784 KiB | ||||
27 | Accepted | 100ms | 28812 KiB | ||||
28 | Accepted | 104ms | 28784 KiB | ||||
29 | Runtime error | 59ms | 64296 KiB | ||||
30 | Runtime error | 61ms | 64296 KiB | ||||
31 | Runtime error | 61ms | 64204 KiB | ||||
32 | Runtime error | 57ms | 64208 KiB | ||||
subtask5 | 0/35 | ||||||
33 | Accepted | 90ms | 27084 KiB | ||||
34 | Accepted | 90ms | 27232 KiB | ||||
35 | Accepted | 94ms | 27508 KiB | ||||
36 | Accepted | 90ms | 27756 KiB | ||||
37 | Accepted | 14ms | 9672 KiB | ||||
38 | Accepted | 48ms | 28292 KiB | ||||
39 | Accepted | 104ms | 28532 KiB | ||||
40 | Accepted | 103ms | 28792 KiB | ||||
41 | Accepted | 104ms | 28784 KiB | ||||
42 | Accepted | 100ms | 28812 KiB | ||||
43 | Accepted | 104ms | 28784 KiB | ||||
44 | Runtime error | 59ms | 64296 KiB | ||||
45 | Runtime error | 61ms | 64296 KiB | ||||
46 | Runtime error | 61ms | 64204 KiB | ||||
47 | Runtime error | 57ms | 64208 KiB | ||||
48 | Runtime error | 67ms | 63996 KiB | ||||
49 | Runtime error | 92ms | 63968 KiB | ||||
50 | Runtime error | 79ms | 63688 KiB | ||||
51 | Runtime error | 92ms | 63432 KiB | ||||
52 | Runtime error | 79ms | 63460 KiB |