#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
struct point {
int x, y;
int id;
point() : x(0), y(0), id(-1) {}
point(int x_, int y_, int id_) :
x(x_), y(y_), id(id_) {}
};
int sg(int x) {
if(x < 0) {
return -1;
}
if(x > 0) {
return 1;
}
return 0;
}
int direction(point a, point b, point c) {
return sg((c.y - a.y) * (b.x - a.x) - (b.y - a.y) * (c.x - a.x));
}
bool between(point a, point b, point c) {
return c.x >= min(a.x, b.x) && c.x <= max(a.x, b.x) && c.y >= min(a.y, b.y) && c.y <= max(a.y, b.y);
}
bool on_segment(point a, point b, point c) {
return direction(a, b, c) == 0 && between(a, b, c);
}
bool intersect(point a, point b, point c, point d) {
return on_segment(a, b, c) || on_segment(a, b, d) || on_segment(c, d, a) || on_segment(c, d, b)
|| (direction(a, b, c) * direction(a, b, d) == -1 && direction(c, d, a) * direction(c, d, b) == -1);
}
const int maxn = 1000;
const int inf = 1e9 + 7;
const point far = point(1, -inf, -1);
const point origin = point(0, 0, -1);
int n;
point points[1 + maxn];
unsigned int dist[1 + maxn][1 + maxn];
bool intersects[1 + maxn][1 + maxn];
int vis[1 + maxn];
unsigned int len;
int cur_comp;
void dfs(int cur) {
vis[cur] = cur_comp;
for(int nei = 1; nei <= n; nei++) {
if(nei == cur || vis[nei] || dist[cur][nei] > len || intersects[cur][nei]) {
continue;
}
dfs(nei);
}
}
bool good(unsigned int cur_len) {
len = cur_len;
cur_comp = 0;
for(int i = 1; i <= n; i++) {
vis[i] = false;
}
for(int i = 1; i <= n; i++) {
if(!vis[i]) {
cur_comp++;
dfs(i);
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(i != j && vis[i] == vis[j] && intersects[i][j]) {
return true;
}
}
}
return false;
}
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> points[i].x >> points[i].y;
points[i].id = i;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
dist[i][j] = (points[i].x - points[j].x) * (points[i].x - points[j].x)
+ (points[i].y - points[j].y) * (points[i].y - points[j].y);
intersects[i][j] = intersect(points[i], points[j], origin, far);
}
}
unsigned int l = 0, r = 8e18 + 1;
while(l < r - 1) {
unsigned int mid = (l + r) / 2;
if(good(mid)) {
r = mid;
} else {
l = mid;
}
}
if(r == 8e18 + 1) {
cout << "-1\n";
} else {
cout << r << "\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 | 2076 KiB | ||||
2 | Wrong answer | 3ms | 2396 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Wrong answer | 3ms | 2352 KiB | ||||
4 | Accepted | 3ms | 2612 KiB | ||||
5 | Accepted | 3ms | 2728 KiB | ||||
6 | Accepted | 3ms | 2936 KiB | ||||
7 | Wrong answer | 3ms | 3016 KiB | ||||
8 | Wrong answer | 3ms | 3240 KiB | ||||
9 | Accepted | 3ms | 3256 KiB | ||||
10 | Wrong answer | 3ms | 3204 KiB | ||||
11 | Accepted | 3ms | 3412 KiB | ||||
12 | Accepted | 3ms | 3628 KiB | ||||
subtask3 | 0/20 | ||||||
13 | Wrong answer | 3ms | 2352 KiB | ||||
14 | Accepted | 3ms | 2612 KiB | ||||
15 | Accepted | 3ms | 2728 KiB | ||||
16 | Accepted | 3ms | 2936 KiB | ||||
17 | Wrong answer | 3ms | 3016 KiB | ||||
18 | Wrong answer | 3ms | 3240 KiB | ||||
19 | Accepted | 3ms | 3256 KiB | ||||
20 | Wrong answer | 3ms | 3204 KiB | ||||
21 | Accepted | 3ms | 3412 KiB | ||||
22 | Accepted | 3ms | 3628 KiB | ||||
23 | Wrong answer | 3ms | 3804 KiB | ||||
24 | Accepted | 3ms | 3892 KiB | ||||
25 | Wrong answer | 3ms | 3804 KiB | ||||
26 | Wrong answer | 3ms | 3804 KiB | ||||
27 | Accepted | 3ms | 4076 KiB | ||||
28 | Wrong answer | 3ms | 3924 KiB | ||||
29 | Accepted | 3ms | 3812 KiB | ||||
30 | Accepted | 3ms | 3820 KiB | ||||
31 | Accepted | 3ms | 3612 KiB | ||||
subtask4 | 0/20 | ||||||
32 | Wrong answer | 3ms | 2352 KiB | ||||
33 | Accepted | 3ms | 2612 KiB | ||||
34 | Accepted | 3ms | 2728 KiB | ||||
35 | Accepted | 3ms | 2936 KiB | ||||
36 | Wrong answer | 3ms | 3016 KiB | ||||
37 | Wrong answer | 3ms | 3240 KiB | ||||
38 | Accepted | 3ms | 3256 KiB | ||||
39 | Wrong answer | 3ms | 3204 KiB | ||||
40 | Accepted | 3ms | 3412 KiB | ||||
41 | Accepted | 3ms | 3628 KiB | ||||
42 | Wrong answer | 3ms | 3804 KiB | ||||
43 | Accepted | 3ms | 3892 KiB | ||||
44 | Wrong answer | 3ms | 3804 KiB | ||||
45 | Wrong answer | 3ms | 3804 KiB | ||||
46 | Accepted | 3ms | 4076 KiB | ||||
47 | Wrong answer | 3ms | 3924 KiB | ||||
48 | Accepted | 3ms | 3812 KiB | ||||
49 | Accepted | 3ms | 3820 KiB | ||||
50 | Accepted | 3ms | 3612 KiB | ||||
51 | Wrong answer | 4ms | 4808 KiB | ||||
52 | Wrong answer | 4ms | 5068 KiB | ||||
53 | Wrong answer | 4ms | 4944 KiB | ||||
54 | Wrong answer | 4ms | 4892 KiB | ||||
55 | Wrong answer | 4ms | 4880 KiB | ||||
56 | Wrong answer | 6ms | 4992 KiB | ||||
57 | Wrong answer | 6ms | 5008 KiB | ||||
58 | Wrong answer | 6ms | 5084 KiB | ||||
59 | Wrong answer | 6ms | 5084 KiB | ||||
60 | Wrong answer | 6ms | 5212 KiB | ||||
61 | Accepted | 6ms | 5212 KiB | ||||
62 | Wrong answer | 6ms | 5292 KiB | ||||
63 | Wrong answer | 6ms | 5284 KiB | ||||
64 | Wrong answer | 6ms | 5412 KiB | ||||
65 | Wrong answer | 6ms | 5408 KiB | ||||
66 | Accepted | 4ms | 5304 KiB | ||||
67 | Accepted | 6ms | 5288 KiB | ||||
68 | Accepted | 6ms | 5404 KiB | ||||
69 | Accepted | 6ms | 5404 KiB | ||||
70 | Accepted | 6ms | 5408 KiB | ||||
subtask5 | 0/40 | ||||||
71 | Wrong answer | 3ms | 2352 KiB | ||||
72 | Accepted | 3ms | 2612 KiB | ||||
73 | Accepted | 3ms | 2728 KiB | ||||
74 | Accepted | 3ms | 2936 KiB | ||||
75 | Wrong answer | 3ms | 3016 KiB | ||||
76 | Wrong answer | 3ms | 3240 KiB | ||||
77 | Accepted | 3ms | 3256 KiB | ||||
78 | Wrong answer | 3ms | 3204 KiB | ||||
79 | Accepted | 3ms | 3412 KiB | ||||
80 | Accepted | 3ms | 3628 KiB | ||||
81 | Wrong answer | 3ms | 3804 KiB | ||||
82 | Accepted | 3ms | 3892 KiB | ||||
83 | Wrong answer | 3ms | 3804 KiB | ||||
84 | Wrong answer | 3ms | 3804 KiB | ||||
85 | Accepted | 3ms | 4076 KiB | ||||
86 | Wrong answer | 3ms | 3924 KiB | ||||
87 | Accepted | 3ms | 3812 KiB | ||||
88 | Accepted | 3ms | 3820 KiB | ||||
89 | Accepted | 3ms | 3612 KiB | ||||
90 | Wrong answer | 4ms | 4808 KiB | ||||
91 | Wrong answer | 4ms | 5068 KiB | ||||
92 | Wrong answer | 4ms | 4944 KiB | ||||
93 | Wrong answer | 4ms | 4892 KiB | ||||
94 | Wrong answer | 4ms | 4880 KiB | ||||
95 | Wrong answer | 6ms | 4992 KiB | ||||
96 | Wrong answer | 6ms | 5008 KiB | ||||
97 | Wrong answer | 6ms | 5084 KiB | ||||
98 | Wrong answer | 6ms | 5084 KiB | ||||
99 | Wrong answer | 6ms | 5212 KiB | ||||
100 | Accepted | 6ms | 5212 KiB | ||||
101 | Wrong answer | 6ms | 5292 KiB | ||||
102 | Wrong answer | 6ms | 5284 KiB | ||||
103 | Wrong answer | 6ms | 5412 KiB | ||||
104 | Wrong answer | 6ms | 5408 KiB | ||||
105 | Accepted | 4ms | 5304 KiB | ||||
106 | Accepted | 6ms | 5288 KiB | ||||
107 | Accepted | 6ms | 5404 KiB | ||||
108 | Accepted | 6ms | 5404 KiB | ||||
109 | Accepted | 6ms | 5408 KiB | ||||
110 | Wrong answer | 173ms | 21748 KiB | ||||
111 | Wrong answer | 164ms | 21752 KiB | ||||
112 | Wrong answer | 163ms | 21784 KiB | ||||
113 | Wrong answer | 168ms | 21896 KiB | ||||
114 | Wrong answer | 177ms | 21796 KiB | ||||
115 | Wrong answer | 172ms | 21784 KiB | ||||
116 | Wrong answer | 261ms | 21808 KiB | ||||
117 | Wrong answer | 284ms | 21848 KiB | ||||
118 | Wrong answer | 345ms | 21816 KiB | ||||
119 | Wrong answer | 287ms | 21948 KiB | ||||
120 | Wrong answer | 293ms | 21888 KiB | ||||
121 | Wrong answer | 282ms | 21776 KiB | ||||
122 | Wrong answer | 250ms | 21776 KiB | ||||
123 | Wrong answer | 252ms | 21748 KiB | ||||
124 | Wrong answer | 247ms | 21748 KiB | ||||
125 | Wrong answer | 240ms | 21784 KiB | ||||
126 | Wrong answer | 303ms | 21752 KiB | ||||
127 | Accepted | 256ms | 21748 KiB | ||||
128 | Accepted | 321ms | 21736 KiB | ||||
129 | Accepted | 204ms | 21752 KiB | ||||
130 | Accepted | 252ms | 21744 KiB | ||||
131 | Accepted | 263ms | 21788 KiB | ||||
132 | Accepted | 266ms | 21788 KiB |