#include <bits/stdc++.h>
#define xy pair<ll, ll>
using ll = long long;
using namespace std;
const int MAXN = 1001;
const ll INF = 1e8;
struct Edge {
ll dist; int u, v;
bool cross;
};
int dsu[2*MAXN];
vector<xy> points;
vector<Edge> edges;
int find(int u) {
return dsu[u]==u?u:dsu[u]=find(dsu[u]);
}
void unio(int u, int v) {
u = find(u); v = find(v);
if (u != v) {
dsu[u] = v;
}
}
bool cross(ll x1, ll y1, ll x2, ll y2) {
return x1*y2 - x2*y1 < 0;
}
int main() {
cin.sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
iota(dsu, dsu+2*MAXN, 0);
for (int i = 1; i <= n; i++) {
ll x, y; cin >> x >> y;
points.emplace_back(x, y);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
Edge e;
e.u = i; e.v = j;
auto [x1, y1] = points[i];
auto [x2, y2] = points[j];
ll dx = x1 - x2;
ll dy = y1 - y2;
e.dist = dx*dx + dy*dy;
if (y1 > y2) {
swap(x1, x2);
swap(y1, y2);
}
if (y1 <= 0 && y2 > 0 && cross(-x1, -y1, x2-x1, y2-y1)) e.cross = true;
else e.cross = false;
edges.emplace_back(e);
}
}
sort(edges.begin(), edges.end(), [](Edge a, Edge b){
return a.dist < b.dist;
});
for (Edge e : edges) {
if (e.cross) {
unio(e.u, e.v+n);
unio(e.u+n, e.v);
} else {
unio(e.u, e.v);
unio(e.u+n, e.v+n);
}
if (find(e.u) == find(e.u+n) || find(e.v) == find(e.v+n)) {
cout << e.dist << "\n";
return 0;
}
}
cout << "-1\n";
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1904 KiB | ||||
2 | Accepted | 3ms | 2104 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2444 KiB | ||||
4 | Accepted | 3ms | 2500 KiB | ||||
5 | Accepted | 3ms | 2588 KiB | ||||
6 | Accepted | 3ms | 2676 KiB | ||||
7 | Accepted | 3ms | 2808 KiB | ||||
8 | Accepted | 3ms | 3040 KiB | ||||
9 | Accepted | 3ms | 3388 KiB | ||||
10 | Accepted | 3ms | 3484 KiB | ||||
11 | Accepted | 3ms | 3696 KiB | ||||
12 | Accepted | 3ms | 3768 KiB | ||||
subtask3 | 20/20 | ||||||
13 | Accepted | 3ms | 2444 KiB | ||||
14 | Accepted | 3ms | 2500 KiB | ||||
15 | Accepted | 3ms | 2588 KiB | ||||
16 | Accepted | 3ms | 2676 KiB | ||||
17 | Accepted | 3ms | 2808 KiB | ||||
18 | Accepted | 3ms | 3040 KiB | ||||
19 | Accepted | 3ms | 3388 KiB | ||||
20 | Accepted | 3ms | 3484 KiB | ||||
21 | Accepted | 3ms | 3696 KiB | ||||
22 | Accepted | 3ms | 3768 KiB | ||||
23 | Accepted | 3ms | 3772 KiB | ||||
24 | Accepted | 3ms | 3844 KiB | ||||
25 | Accepted | 3ms | 3852 KiB | ||||
26 | Accepted | 2ms | 3856 KiB | ||||
27 | Accepted | 3ms | 3944 KiB | ||||
28 | Accepted | 3ms | 4080 KiB | ||||
29 | Accepted | 2ms | 3980 KiB | ||||
30 | Accepted | 3ms | 4056 KiB | ||||
31 | Accepted | 3ms | 3792 KiB | ||||
subtask4 | 20/20 | ||||||
32 | Accepted | 3ms | 2444 KiB | ||||
33 | Accepted | 3ms | 2500 KiB | ||||
34 | Accepted | 3ms | 2588 KiB | ||||
35 | Accepted | 3ms | 2676 KiB | ||||
36 | Accepted | 3ms | 2808 KiB | ||||
37 | Accepted | 3ms | 3040 KiB | ||||
38 | Accepted | 3ms | 3388 KiB | ||||
39 | Accepted | 3ms | 3484 KiB | ||||
40 | Accepted | 3ms | 3696 KiB | ||||
41 | Accepted | 3ms | 3768 KiB | ||||
42 | Accepted | 3ms | 3772 KiB | ||||
43 | Accepted | 3ms | 3844 KiB | ||||
44 | Accepted | 3ms | 3852 KiB | ||||
45 | Accepted | 2ms | 3856 KiB | ||||
46 | Accepted | 3ms | 3944 KiB | ||||
47 | Accepted | 3ms | 4080 KiB | ||||
48 | Accepted | 2ms | 3980 KiB | ||||
49 | Accepted | 3ms | 4056 KiB | ||||
50 | Accepted | 3ms | 3792 KiB | ||||
51 | Accepted | 3ms | 4604 KiB | ||||
52 | Accepted | 3ms | 4564 KiB | ||||
53 | Accepted | 3ms | 4500 KiB | ||||
54 | Accepted | 3ms | 4508 KiB | ||||
55 | Accepted | 3ms | 4524 KiB | ||||
56 | Accepted | 3ms | 4528 KiB | ||||
57 | Accepted | 3ms | 4768 KiB | ||||
58 | Accepted | 3ms | 4788 KiB | ||||
59 | Accepted | 3ms | 4776 KiB | ||||
60 | Accepted | 3ms | 5048 KiB | ||||
61 | Accepted | 3ms | 5008 KiB | ||||
62 | Accepted | 3ms | 5272 KiB | ||||
63 | Accepted | 3ms | 5224 KiB | ||||
64 | Accepted | 3ms | 5144 KiB | ||||
65 | Accepted | 3ms | 5408 KiB | ||||
66 | Accepted | 3ms | 5368 KiB | ||||
67 | Accepted | 3ms | 5376 KiB | ||||
68 | Accepted | 3ms | 5372 KiB | ||||
69 | Accepted | 3ms | 5632 KiB | ||||
70 | Accepted | 3ms | 5592 KiB | ||||
subtask5 | 40/40 | ||||||
71 | Accepted | 3ms | 2444 KiB | ||||
72 | Accepted | 3ms | 2500 KiB | ||||
73 | Accepted | 3ms | 2588 KiB | ||||
74 | Accepted | 3ms | 2676 KiB | ||||
75 | Accepted | 3ms | 2808 KiB | ||||
76 | Accepted | 3ms | 3040 KiB | ||||
77 | Accepted | 3ms | 3388 KiB | ||||
78 | Accepted | 3ms | 3484 KiB | ||||
79 | Accepted | 3ms | 3696 KiB | ||||
80 | Accepted | 3ms | 3768 KiB | ||||
81 | Accepted | 3ms | 3772 KiB | ||||
82 | Accepted | 3ms | 3844 KiB | ||||
83 | Accepted | 3ms | 3852 KiB | ||||
84 | Accepted | 2ms | 3856 KiB | ||||
85 | Accepted | 3ms | 3944 KiB | ||||
86 | Accepted | 3ms | 4080 KiB | ||||
87 | Accepted | 2ms | 3980 KiB | ||||
88 | Accepted | 3ms | 4056 KiB | ||||
89 | Accepted | 3ms | 3792 KiB | ||||
90 | Accepted | 3ms | 4604 KiB | ||||
91 | Accepted | 3ms | 4564 KiB | ||||
92 | Accepted | 3ms | 4500 KiB | ||||
93 | Accepted | 3ms | 4508 KiB | ||||
94 | Accepted | 3ms | 4524 KiB | ||||
95 | Accepted | 3ms | 4528 KiB | ||||
96 | Accepted | 3ms | 4768 KiB | ||||
97 | Accepted | 3ms | 4788 KiB | ||||
98 | Accepted | 3ms | 4776 KiB | ||||
99 | Accepted | 3ms | 5048 KiB | ||||
100 | Accepted | 3ms | 5008 KiB | ||||
101 | Accepted | 3ms | 5272 KiB | ||||
102 | Accepted | 3ms | 5224 KiB | ||||
103 | Accepted | 3ms | 5144 KiB | ||||
104 | Accepted | 3ms | 5408 KiB | ||||
105 | Accepted | 3ms | 5368 KiB | ||||
106 | Accepted | 3ms | 5376 KiB | ||||
107 | Accepted | 3ms | 5372 KiB | ||||
108 | Accepted | 3ms | 5632 KiB | ||||
109 | Accepted | 3ms | 5592 KiB | ||||
110 | Accepted | 82ms | 29848 KiB | ||||
111 | Accepted | 82ms | 29860 KiB | ||||
112 | Accepted | 82ms | 29912 KiB | ||||
113 | Accepted | 82ms | 29920 KiB | ||||
114 | Accepted | 82ms | 29936 KiB | ||||
115 | Accepted | 86ms | 29988 KiB | ||||
116 | Accepted | 86ms | 30032 KiB | ||||
117 | Accepted | 85ms | 30028 KiB | ||||
118 | Accepted | 85ms | 30040 KiB | ||||
119 | Accepted | 85ms | 30064 KiB | ||||
120 | Accepted | 85ms | 30112 KiB | ||||
121 | Accepted | 90ms | 30116 KiB | ||||
122 | Accepted | 90ms | 30148 KiB | ||||
123 | Accepted | 90ms | 30184 KiB | ||||
124 | Accepted | 90ms | 30172 KiB | ||||
125 | Accepted | 86ms | 30224 KiB | ||||
126 | Accepted | 90ms | 30240 KiB | ||||
127 | Accepted | 90ms | 30288 KiB | ||||
128 | Accepted | 92ms | 30344 KiB | ||||
129 | Accepted | 90ms | 30484 KiB | ||||
130 | Accepted | 90ms | 30480 KiB | ||||
131 | Accepted | 76ms | 30744 KiB | ||||
132 | Accepted | 93ms | 30752 KiB |